Runtime.getRuntime().exec hangs and doesn't print the output
807591Mar 25 2008 — edited Mar 27 2008Hi,
I have written the following code to execute the command "psexec ipaddress -u userid -p password -l -c execute.exe >> c:/25_showoutpout.txt" and print the output in 25_showoutpout.txt file.
import java.io.*;
public class ExecTest{
public static void main(String args[]) throws IOException{
String args1 = "psexec ipaddress -u userid -p password -l -c execute.exe >> c:/25_showoutpout.txt";
try{
Process p=Runtime.getRuntime().exec(args1);
int i = p.waitFor();
System.out.println("Done.with time "+i);
}catch(Exception e){
System.out.println("The error is "+e);
}
}
}
But this program hangs and creates a blank 25_showoutpout.txt file.In the process list I can see the process running, but it doesn't redirect the output in the txt file.When i run the command from the command line it runs fine.Please help me.
Thanks in advance