先来看一下ProcessBuilder类这段DOC
* <blockquote><pre>
* Process p = new ProcessBuilder("myCommand", "myArg").start();
* </pre></blockquote>
*
* <p>Here is an example that starts a process with a modified working
* directory and environment:
*
* <blockquote><pre>
* ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
* Map<String, String> env = pb.environment();
* env.put("VAR1", "myValue");
* env.remove("OTHERVAR");
* env.put("VAR2", env.get("VAR1") + "suffix");
* pb.directory(new File("myDir"));
* Process p = pb.start();
* </pre></blockquote>
*
* <p>To start a process with an explicit set of environment
* variables, first call {@link java.util.Map#clear() Map.clear()}
* before adding environment variables.
*
* @since 1.5
*/
public final class ProcessBuilder
{
按这个例子改完之后怎么运行都报错:
Exception in thread "main" java.io.IOException: Cannot run program "ffmpeg.exe": CreateProcess error=2
at java.lang.ProcessBuilder.start(Unknown Source)
再看一下环境变量:
new ProcessBuilder().environment()
path根本没有改变!
google发现了这篇文章:
http://weblog.dangertree.net/2007/04/13/changing-path-and-environment-in-java-processbuilder/
引用
The first and most important issue is this: Changes to the Path environment variable are not reflected until a new process is created and running. Here is an example of how this can bite you in the ass:
ProcessBuilder pb =
new ProcessBuilder(”myExe.exe”, “arg1″, “arg2″);
Map env = pb.environment();
// watch out here! this could be “PATH” or “path”
// Windows doesn’t care, but Java will
String path = env.get(”Path”);
env.set(”Path”, path + File.pathSeparator
+ “path\to\the\executable”);
pb.start();
1.You have an executable file that you want to run with ProcessBuilder that is not on your path.
2.You assume that you can write the previous code in order to temporarily add the exe’s path to the process’s environment before executing it.
3.You always get an error=2 back from the ProcessBuilder because it cannot find the file.
This is because the changes you made to the new process environment are not reflected until the process is actually running. In other words, Java does not change the path until it attempts to execute the command you have told it to execute. It will never find an executable file that is not on the previous system path even if you change the “Path” environment variable in the ProcessBuilder before you call the “start()” method.
浪费了小半个下午的时间!
分享到:
相关推荐
kickass.to]big.hero.6.2014.1080p.bluray.x264.sparks.torre
通过选择文本来搜索torrent的方式 此扩展名使您可以选择页面上的文本,右键单击它,然后在Kickass种子文件中搜索该文本。 支持语言:English
Kickass Undelete是一个的文件恢复工具,可快速查找并恢复已删除的文件。程序能极其快速地扫描并列出文件名称、 文件类型、 大小、 修改日期、 路径,你可以看到能够恢复的文件
资源来自pypi官网。 资源全名:kickass-get-0.2.3.tar.gz
Kickass Undelete是Windows的免费,功能齐全的文件恢复工具。 不小心删除了文件? 从不畏惧; 数据可能仍在驱动器上,并且可以恢复。 Kickass Undelete会在硬盘,闪存驱动器或SD卡上找到所有已删除的文件,并允许您...
AutoTorrentCrawler Torrent爬虫程序从kickass.io获得一点洪流,然后启动uTorrent自动下载###关于在这个项目中,我编写了一个Scrapy爬虫,该爬虫使用kickass.io的get bit torrent并启动uTorrent来自动下载任何...
KickAss备份解析器 此类允许您下载和解析每日和每小时的KickAss torrent数据库备份。 更新KickAssTorrent已更改其TOS现在您需要填写访问其备份的请求,因此该类已被弃用。 演示版 $ kickass = new KickAss (); $ ...
资源分类:Python库 所属语言:Python 资源全名:kickass-get-0.1.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
改进了KickassTorrents(kat)的用户界面。 改进了KickassTorrents(kat)的用户界面。 这个扩展: - 突出显示最近上传的种子; - 自动隐藏标签云。 建议@ http://git.io/vTsDX ...支持语言:English
主题编织者Themeweaver是一个Web应用程序,使用设计令牌创建IDE和语法突出显示主题。关于该项目使用许多开源项目。 它是使用Create-React-App构建的。贡献去吧。 1个人在空闲时间做这是一件愚蠢的事情,因为他们觉得...
只要选择任何网站的电影名称,然后点击按钮,这个插件将自动打开一个新的标签,并在Kickass.org中搜索电影。如果电影名称包含中文,则使用豆瓣api将其翻译成英文,然后在kickass.org中搜索。 请让我知道,如果你有...
语言:English 改进了KickassTorrents(kat)的用户界面。 改进了KickassTorrents(kat)的用户界面。 此扩展名:-突出显示最近上传的种子; -自动隐藏标签云。 建议@ http://git.io/vTsDX海盗湾UI-...
VSCode KickAss(C64) Visual Studio Code语言支持使用进行C64开发。 这受软件包的启发,该软件包由的全能编码。 这就是复制.tmLanguage文件的位置。 此外,通过非常鼓舞 ,通过由感谢你们俩! 像是1988年的代码!...
前端项目-popper.js,A kickass library to manage your poppers
RedirectBot是一种将导出的Google crawlerror csv文件快速转换为.htaccess重定向的工具。
只需在任何网站上选择电影名称,然后单击按钮,此插件将自动打开一个新标签并在Kickass.org中搜索电影。 如果电影名称包含中文,它将使用Douban api将名称翻译成英语,然后在kickass.org中搜索。 如果您有任何令人...
引领Kickass 主导的项目班级说明:监视器存储共享数据
Kickass动漫寻找可以观看各种内容的动漫网站,Kickass动漫是理想的去处。 在这里,您会发现各种动漫,包括喜剧,体育,科幻,戏剧等。 您可以免费观看网站上所有类型的动漫。 此外,您还可以根据观看时获得的经验对...
KickassAPI 另一个节点kickass api
去劲爆Go Kickass 是事实上的标准 Go 包的集成,可让您快速引导一个坚如磐石的 Web 应用程序。背景这个想法是每次你需要启动一个新的 Web 项目时,你都可以分叉这个存储库。 当我在 2014 年底开始学习 Go back 时,...