Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Runtime.getRuntime().exec

Reply
Thread Tools

Runtime.getRuntime().exec

 
 
ilya
Guest
Posts: n/a
 
      04-19-2010
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?
 
Reply With Quote
 
 
 
 
Mike Amling
Guest
Posts: n/a
 
      04-19-2010
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
 
Reply With Quote
 
 
 
 
Ilya Lakhmitski
Guest
Posts: n/a
 
      04-19-2010
ok. Thank you for the explanations.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments