0

I have trouble with the following situation:

I want to run a process using ProcessBuilder in Java. The code as it is used to work on other computers and is very basic. But now, if I run the program in Eclipse, the executable called, gives me an error with only information being the Path variable. But nevertheless, if I export the project as a jar file, the program works fine! I already checked all path variables with the computer where it works, and all are included in the processbuilder while running in eclipse (I checked ProcessBuilder.environment()) , but for some strange reason this just won't work.

As I said, the code is really basic and works if it was exported as a jar:

String [] cmdArr = cmd.split("\\s+");
ProcessBuilder pb = new ProcessBuilder(cmdArr);
Process p;
p = pb.start();
p.waitFor();

Also if I call the project from another project, the result is the same behaviour: not working, until exported as a jar.

Again: all Path variables are appended.

I would be very grateful, if someone could give a hint into the right direction.

My computer is running Windows 7 x64, Eclipse Kepler Service Release 1, JDK 1.8.0_05 x64

I could not find anything by searching for similar problems, since including "path" in the search yields many popular problems about java not working or setting path variables for runs and on the other hand "Running as a jar but not in Eclipse" (and similar searches) only provide the contrary, namely something running in Eclipse, stops working as an exported jar. But those are all rather easy problems, and unfortunately don't help me.

Thanks in advance

Dan

  • what's the content of `cmd` and what's the exact error message? – Moh-Aw Jun 10 '14 at 13:48
  • Unfortunately the error message is produced by the external executable and is not very informative. It just has the heading "Error" and as content only "PATH=C:[...]" the whole Path variable. The cmd is alright it is just "c:\\abc\\win\\abcbatch argument" – Daniel Valenzuela Jun 10 '14 at 14:25

2 Answers2

0

are you using a relative path to the executable to launch?

eclipse will use a different current directory than the jar launch folder itself to launch it.

if this is the cause, you can diagnose it by logging where the current directory points to:

String current = new java.io.File( "." ).getCanonicalPath();
Lorenzo Boccaccia
  • 6,041
  • 2
  • 19
  • 29
  • This is a good advice, but the executable has a static directory and therefore I use the absolute path. – Daniel Valenzuela Jun 10 '14 at 14:28
  • it might be, but it will run with the aforementioned working directory itself; see http://stackoverflow.com/questions/8405723/how-to-set-working-directory-with-processbuilder – Lorenzo Boccaccia Jun 10 '14 at 15:02
0

So it seems, that the problem was -- unfortunately more precisely: is -- the executable. This is, since sometimes the same error message pops up, while running the exported version. I didn't want to believe this, because of the differences in project runs/jar runs stated in the question existed. Hence there is something supporting this error, even though it turned out to be irrelevant.

Cheers