JavaGeek
JavaGeek

Reputation: 1539

unable to run command prompt using java

I'm just trying to open a command prompt window using java program (in eclipse). When i run pgm as below, it's not showing any message

Runtime.getRuntime().exec("cmd");

But when i try to open internet explorer using below line

Runtime.getRuntime().exec("iexplore");

It's throwing below error

Exception in thread "main" java.io.IOException: CreateProcess: iexplore error=2
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at dev.petrofac.ChangeFilePermission.main(ChangeFilePermission.java:17)

Upvotes: 0

Views: 2748

Answers (2)

Patrick
Patrick

Reputation: 17973

The fact is that you are starting cmd. Just because you can't see it doesn't mean it doesn't start.

If you want to see the output from the application, you need to get the outputstream (see Process for details). If you want to start cmd in a new window you can execute the string "cmd.exe /c start cmd.exe" instead, as in

Runtime.getRuntime().exec("cmd.exe /c start cmd.exe");

Upvotes: 4

A Null Pointer
A Null Pointer

Reputation: 2277

Try checking the file permissions for iexplore.

Allow execute privileges for all processes/users , if not set already.

Upvotes: 0

Related Questions