From: ilya on 19 Apr 2010 06:19 I try to execute the command: Runtime.getRuntime().exec("%ComSpec% /c start calc") and java gives me the error: java.io.IOException: Cannot run program "%ComSpec%": CreateProcess error=2, The system can not find the file specified. But if I execute in such way Runtime.getRuntime().exec("cmd /c start calc"), all is ok. What is the reason?
From: Mike Amling on 19 Apr 2010 10:18 ilya wrote: > I try to execute the command: Runtime.getRuntime().exec("%ComSpec% /c > start calc") and java gives me the error: > java.io.IOException: Cannot run program "%ComSpec%": CreateProcess > error=2, The system can not find the file specified. > > But if I execute in such way Runtime.getRuntime().exec("cmd /c start > calc"), all is ok. > > What is the reason? It's the shell (cmd.exe) that substitutes values of environmental variables for their percentified names. When you issue exec("%ComSpec%..."), there is not yet any cmd.exe running that would perform the substitution. You could issue getenv("ComSpec") yourself and use the returned value instead of "cmd". --Mike Amling
From: Ilya Lakhmitski on 19 Apr 2010 10:20 ok. Thank you for the explanations.
|
Pages: 1 Prev: Java socket.... Next: add jar to classpath at runtime but not able to access resource in jar |