From: ilya on
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
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
ok. Thank you for the explanations.