• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime.exec().  RSS feed

 
Sajan Patel
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • 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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Joe Ess
Bartender
Posts: 9439
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Dean Jones
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!