1

Here is my code and I am not sure why the following error is coming up:

 Opening firefox at Sun Oct 28 21:45:27 EDT 2012 java.io.IOException: Cannot run program "firefox.exe": CreateProcess error=2, The system cannot find the file specified public static void open(String app) { try { Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); System.out.println("Opening " + app + " at " + now); ProcessBuilder builder = new ProcessBuilder(app+".exe"); builder.start(); } catch (IOException e) { System.out.println(e); } } 

Any suggestions?

3
  • 3
    What does "The system cannot find the file specified" mean to you? Commented Oct 29, 2012 at 1:50
  • I inputted "firefox". I tried to run firefox from the command prompt and it worked. Why wouldn't it here? Commented Oct 29, 2012 at 1:51
  • 1
    It looks like the application can't be found. If the application does not exist in the current system path, you need to supply the path to the executable. Try something like System.out.println(new File(app + ".exe").exists()); and see if the file exists within the location you are running from (or as specified by the path supplied with the app String) Commented Oct 29, 2012 at 1:52

1 Answer 1

3

You have to specify the full path to the Firefox executable.

Sign up to request clarification or add additional context in comments.

4 Comments

There has to be a simpler way of doing that than actually specifying every possible file path.. How can I do this efficiently?
unfortunately it seems that ProcessBuilder ignores the system default paths.
is there an argument I can add to not ignore them?
@phileaton - you're not using a shell. There's no such thing as a "search path". You have to specify where the file is you wish to execute.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.