Javaruntime.exec导致程序崩溃
我正在尝试使用 java 运行外部程序 Decoder.exe: Runtime.getRuntime().exec("C:\fullpath-and-so-on\Decoder.exe -h");就像这样:
try{
Process p = Runtime.getRuntime().exec("C:\\fullpath-and-so-on\\Decoder.exe -h");
}
catch(Exception e){
e.printStackTrace();
}
这适用于我尝试过的所有其他程序。但每当我从 java 执行它时,Decoder.exe 就会崩溃。 java 执行正常并且不会产生任何异常,但被调用的程序 Decodes.exe 停止工作。当在单独的 cmd 窗口中运行时,程序 Decoder.exe 可以完美执行。
有没有人有类似问题的经验? java运行exec和程序在cmd.exe中运行有什么不同?是否有已知的解决方法或者我只是在某个地方犯了错误?
非常感谢您的帮助! BR, 弗雷德里克
I am trying to run an external program Decoder.exe using a java:
Runtime.getRuntime().exec("C:\fullpath-and-so-on\Decoder.exe -h"); like so:
try{
Process p = Runtime.getRuntime().exec("C:\\fullpath-and-so-on\\Decoder.exe -h");
}
catch(Exception e){
e.printStackTrace();
}
This works for all other programs I've tried. But whenever I execute it from java the Decoder.exe crashes. The java executes fine and does not generate any exceptions but the called program Decodes.exe stops working. The program Decoder.exe executes perfectly when run in a separate cmd window.
Have anyone had any experience with a similar problem? What differs when java runs exec and when a program is run in cmd.exe? Is there a known workaround or am I just making a mistake somewhere?
Very thankful for any help!
BR,
Fredrik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你说停止工作?
Decoder.exe 是否将输出写入 stderr 或 stdout?在这种情况下,您必须读取这些流,因为流的缓冲区非常小,如果这些缓冲区已满,执行将停止。
这是一篇很棒的文章,虽然很旧,但仍然有效:
当 Runtime.exec() 不会运行时
Stops working you say?
Is the decoder.exe writing output to stderr or stdout? You must in that case read those streams, since the buffers for the streams are very small, and the execution will halt if those buffers get full.
This is a great article, it's old, but it still holds:
When Runtime.exec() won't
本教程可以帮助您 http ://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1
和
ProcessBuilder
和
Oracle API
也许是我的问题 将字符串作为参数从一个 Java 应用程序传递到另一个应用程序
this tutorial can help you with that http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1
and
ProcessBuilder
and
Oracle API
maybe my question Pass String as params from one Java App to another