简体   繁体   English

Java runtime.exec 导致程序崩溃

[英]Java runtime.exec causes program crash

I am trying to run an external program Decoder.exe using a java: Runtime.getRuntime().exec("C:\fullpath-and-so-on\Decoder.exe -h");我正在尝试使用 java 运行外部程序Decoder.exe : 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.但是每当我从 java 执行它时,Decoder.exe 就会崩溃。 The java executes fine and does not generate any exceptions but the called program Decodes.exe stops working. java 执行良好,不会产生任何异常,但被调用程序 Decodes.exe 停止工作。 The program Decoder.exe executes perfectly when run in a separate cmd window.程序 Decoder.exe 在单独的 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? java 运行 exec 和程序在 cmd.exe 中运行时有何不同? Is there a known workaround or am I just making a mistake somewhere?是否有已知的解决方法,或者我只是在某个地方犯了错误?

Very thankful for any help, BR, Fredrik非常感谢您的帮助,BR,Fredrik

Stops working you say?你说停止工作?

Is the decoder.exe writing output to stderr or stdout?解码器.exe 是否将 output 写入标准错误或标准输出? 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这是一篇很棒的文章,它很旧,但它仍然有效:当 Runtime.exec() 不会

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM