Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running remote shell script from Java using Runtime 1

Status
Not open for further replies.

SilverStray

Programmer
Oct 25, 2001
47
AU
Hi,

I am having trouble running a shell script from Java, using the Runtime.exec.

In simple illustration, the following code works ok if i execute the class on the same directory as the Shell script "runprog.ksh" is.


String commandScript = "runprog.ksh 'param1'"
final Process process = Runtime.getRuntime().exec(commandScript);


But if i execute the Java class on another machine, and execute the script using ssh, how to properly set or which Runtime.exec(<args>) methods should i use?

I have put something like :


String[] command = {"/etc/ssh myUser@remoteServer","runprog.ksh 'param1'"};
final Process process = Runtime.getRuntime().exec(command);


This results to the following error:

java.io.IOException: java.io.IOException: ssh myUser@remoteServer: not found
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)


Pls. help!

Thanks in advance.

SilverStray
 
try:
Code:
String[] command = {"/etc/ssh", "myUser@remoteServer", "runprog.ksh 'param1'"};
 final Process process = Runtime.getRuntime().exec(command);
Your version leads to a search for a program whichs name contains a space /etc/ssh\ myUser@remoteServer .



don't visit my homepage:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top