Commons-exec: Running a program on a PATH system?

I am trying to execute a program (convert from ImageMagick to be specific) whose parent folder exists in the path. Ergo, when I run convert from the command line, it runs the command. However, the following:

 String command = "convert" CommandLine commandLine = CommandLine.parse(command); commandLine.addArgument(...) ... int exitValue = executor.execute(commandLine); 

If I specify the full path to the executable file convert ( C:\Program files\... ), then this code works. If I do not, I get an exception thrown with exit 4 .

How do I get commons-exec to recognize the system path?

+4
source share
1 answer

I ran into issues such that the PATH system is not a Java process. To debug this, you can print out what the Java process sees as the env variable of the path using:

 EnvironmentUtils.getProcEnvironment(); 

Which will give you a map, and you can see if Java can see the path variable. If this does not happen, then the next step is to find out why you cannot see it.

If it is, I will try to run the excutor.execute command as follows:

 int exitValue = executor.execute(commandLine, EnvironmentUtils.getProcEnvironment()); 
+7
source

Source: https://habr.com/ru/post/1307707/


All Articles