简体   繁体   中英

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"); 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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