• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Runtime.exec().

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
below is my code for copy one file from one server to another.

Runtime load = Runtime.getRuntime();
String sFileName = /bin/sh -c scp 20041229143332464.csv [UserName]@[192.0.0.1]:/FolderName1/FolderName2/FolderName3
Process process = load.exec(sFileName);

Problemm is It ask for password and I dont know how to pass password after initiating exec command.
Thanks in Advance
Solution Idea
1) For Unix Forum
Do we have any other option then SCP but secure with authentication in which we can pass password with itself (like PSCP does)
2) For JAVA Forum
Can we pass any password in active window after few seconds. Through Runtime.exec().



Thanks in advance

Sajan Patel
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can get the input and output streams from the Process object and interact with the stdin, stdout and errout of the command. It's mildly tricky because you may need separate threads for stdout and errout. I haven't tried this on Unix, don't know how well the OS commands work this way.
 
Sajan Patel
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I tired with
let me tell you more.
When I execute my SCP command after that it ask for password which I have to give it in same window which open for my SCP command
with the Help of
Runtime.exce("scp test.txt [User Name]@192.0.0.1:/Folder/Folder/Folder");
and it stop there for password

$root$>scp test.txt [User Name]@192.0.0.1:/Folder/Folder/Folder
[UserName]@192.0.0.1's password:

now I did something like this
(inside thread)
PrintWriter out = new PrintWriter(process1.getOutputStream());
out.write("PASSWORD");
but sorry this is not working. I am interating with prompt here
[ December 30, 2004: Message edited by: Sajan Patel ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about a carrage return or using writeln() with that password? It's like you are typing the password in but then you don't hit enter.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem is, SCP asks for the password via opening the tty directly in raw form. It's not getting it from STDIN. It does this for a couple of different reasons, which I won't go over here. A workaround for this is to use KEYS for authentication and that way it won't ask for a password at all, but use keys (dsa, rsa, etc...) for authentication.
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic