// following code works fine n open notepad...
class demo
{
public static void main(String args[])
{
try{
ProcessBuilder pb=new ProcessBuilder("notepad");
pb.start();
}catch(Exception e)
{System.out.print(e);}
}
}
//however the above code throws an exception when any other system program is executed
class demo
{
public static void main(String args[])
{
try{
ProcessBuilder pb=new ProcessBuilder("calculator");
pb.start();
}catch(Exception e)
{System.out.print(e);}
}
}
the above program throws following exception:
java.io.IOException: Cannot run program "Calculator": CreateProcess error=2, The system cannot find the file specified
Andrew Thompson
169k42 gold badges224 silver badges441 bronze badges
asked Jan 3, 2012 at 7:34
shubhendu mahajan
8161 gold badge7 silver badges16 bronze badges
1 Answer 1
You should include the full path to the executable (including the directories and the .exe extension).
Should actually be apparent from the error message you got :-)
(The reason "notepad" worked indicates that it will search %PATH% and try to append .exe if necessary. This leads me to believe that "calc" may also work :-)
answered Jan 3, 2012 at 7:37
aioobe
423k115 gold badges831 silver badges844 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-java