Click to See Complete Forum and Search --> : Running specific commands in cmd with java


KingCobra220
10-21-2006, 01:13 AM
I figured out how to run command prompt from java. Now, is there a way to run a specific command prompt command from java?
Here's what I used to run cmd:

try{
Runtime.getRuntime().exec("cmd /c start");
}
catch(IOException e)
{
System.out.println("Failure to Launch cmd.exe");
System.exit(0);
}


I was thinking something like the following would work to run a specific command:

try{
Runtime.getRuntime().exec("cmd /c start ipconfig");
}
catch(IOException e)
{
System.out.println("Failure to Launch ipconfig");
System.exit(0);
}


When running that last bit of code, a DOS window pops up and instantly disappears...any ideas? It worked fine when the command was 'time'.

Thanks in advance for the help.

agent_x91
10-30-2006, 04:26 AM
Maybe it ran ipconfig but was too fast for you to see? Try running a pause command after ipconfig.