Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Runtime.getRuntime().exec hangs and doesn't print the output

807591Mar 25 2008 — edited Mar 27 2008
Hi,
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 24 2008
Added on Mar 25 2008
37 comments
2,189 views