1

I've been struggling to find a reason why my Java application does not use the default PATH environment variable. I need it to launch another program with ProcessBuilder. Right now I get "Cannot run program "..." error=2, No such file or directory", though I can run this program from the terminal. I'm using JDK 1.8, Netbeans 8.1, OS X.

Here's the output of System.out.println(System.getenv("PATH"));: /usr/bin:/bin:/usr/sbin:/sbin

The actual value of PATH in the terminal (using echo $PATH) is much longer and contains the paths to the desired executables.

I found some questions treating on the same subject but none could help me with this.

Any help appreciated!

5
  • How do you run your program? Commented Mar 7, 2016 at 20:11
  • Still in development phase so I'm using Netbeans - Run project. Should I launch it without the IDE? Commented Mar 7, 2016 at 20:24
  • Yes. It could be the Netbeans setting the PATH variable. Commented Mar 7, 2016 at 20:31
  • Damn! You're right. It now uses the correct PATH variable - my executable is launched. Thank you very much for this. Any idea on how to set the environment variables in Netbeans? Couldn't find much info on this! Commented Mar 7, 2016 at 20:47
  • Here you go - stackoverflow.com/a/17238424/738746. Commented Mar 7, 2016 at 20:58

1 Answer 1

1

PATH is created by whatever shell you're running, but ProcessBuilder does notrun within a shell and therefore there isn't a PATH to attach to, to resolve your program names. You can provide an environment to ProcessBuilder, but don't believe it's going to let you find your program that's in the PATH. In a project of mine I had to provide a fully-qualified path.]

[NOTE: Mileage may vary, I seem to remember having somewhat different results between Windows and *nix, and between different *xix.]

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.