Running external program with redirected stdin and stdout from Java

后端 未结 3 1530
温柔的废话
温柔的废话 2020-11-28 11:21

I\'m trying to running an external program from a Java program and I\'m having trouble. Basically what I\'d like to do would be this:

 Runtime.getRuntime().e         


        
3条回答
  •  被撕碎了的回忆
    2020-11-28 12:11

    You could try something like this:

    ProcessBuilder pb = new ProcessBuilder();
    pb.redirectInput(new FileInputStream(new File(infile));
    pb.redirectOutput(new FileOutputStream(new File(outfile));
    pb.command(cmd);
    pb.start().waitFor();
    

提交回复
热议问题