Ruud Schroën
Ruud Schroën

Reputation: 53

ProcessBuilder can't find command, though it can be found in terminal

I have a Java application which starts Mopidy via ProcessBuilder. This is my code:

if(mopidy==null){
     try {
         btnStartMopidy.setDisable(true);
         btnStopMopidy.setDisable(false);
         ProcessBuilder pb = new ProcessBuilder("/bin/bash", "-c", "mopidy");
         pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
         pb.redirectError(ProcessBuilder.Redirect.INHERIT);
         mopidy = pb.start();
     } catch (IOException ex) {
         ex.printStackTrace();
         Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
     }
 }

The weird thing is when I run it from Netbeans, the output says the Mopidy command cannot be found, BUT..

When I run the built .jar file via the terminal, I get the expected Mopidy output. When I run the .jar file by double clicking on it, I get the same error saying the command cannot be found.

Any thoughts?

EDIT:

This time I tried to invoke the program directly instead of using bash -c.

ProcessBuilder pb = new ProcessBuilder("/usr/local/bin/mopidy");

It seems Mopidy can be found now, but I'm getting a different error. It says that a certain Python package (GStreamer, which is required for Mopidy) cannot be found, though it is installed.

Upvotes: 3

Views: 1532

Answers (1)

noor
noor

Reputation: 1691

This is a weird bug in eclipse that never gets fixed. Don't restart your eclipse after adding it to PATH variable. Exit eclipse and start again and it should work.

Upvotes: 2

Related Questions