从Java代码调用C可执行文件后没有得到任何输出

San*_*kar 0 c java process runtime.exec

我正在尝试从已经编译和执行的Java代码执行C代码,但是,我没有从可执行文件中获得任何输出.任何人都可以帮我完成这项任务吗?

代码如下.

public class Test {
    public static void main(String args[]) {
        try {
            Process processCompile = Runtime.getRuntime().exec("e:/Sample.exe");
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Jun*_*san 5

试试这个:

BufferedReader stdInput = new BufferedReader(new 
     InputStreamReader(processCompile .getInputStream()));


// read the output from the command
System.out.println("EXE OUTPUT");
while ((s = stdInput.readLine()) != null) {
    System.out.println(s);
}
Run Code Online (Sandbox Code Playgroud)