commons-exec:在系统上执行程序PATH? [英] commons-exec: Executing a program on the system PATH?

查看:185
本文介绍了commons-exec:在系统上执行程序PATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在路径上执行其父文件夹存在的程序(从ImageMagick转换为具体)。当我从命令行运行 convert 时,它会运行命令。然而,以下内容失败:

I'm trying to execute a program (convert from ImageMagick, to be specific) whose parent folder exists on the path. Ergo, when I run convert from the command line, it runs the command. The following, however, fails:

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

如果我指定convert可执行文件的完整路径( C:\程序文件\ ... ... )然后这个代码工作。如果我不这样做,我会收到一个例外,退出值 4

If I specify the full path of the convert executable (C:\Program files\...) then this code works. If I don't do this, I get an exception thrown with exit value 4.

commons-exec来识别系统路径?

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

推荐答案

我遇到过这样的问题,系统设置PATH不是java进程看到了什么作为一种调试方式,您可以使用以下方式打印java进程看到的路径env变量:

I've run into issues like this before where the system set PATH is not what the java process is seeing. As a way to debug this you can print out what the java process sees as the path env variable by using:

EnvironmentUtils.getProcEnvironment();

哪个会给你一张地图,你可以看看Java是否可以看到路径变量。如果不在那里,那么下一步就是弄清楚为什么你看不到它。

Which will give you a map and you can look to see if Java can see the path variable. If it is not there then the next step would be to figure out why you can't see it.

如果是那里我会尝试运行你的excutor.execute命令如下:

If it is there I would try running your excutor.execute command as follows:

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

这篇关于commons-exec:在系统上执行程序PATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆