External program from our Java program

后端 未结 5 674
半阙折子戏
半阙折子戏 2020-12-11 11:55

How can I write a program in Java that will execute another program? Also, the input of that program should be given from our program and the output of that program should b

5条回答
  •  没有蜡笔的小新
    2020-12-11 12:51

    You can use java.lang.Process and java.lang.ProcessBuilder. You interact with the input/output of the process using getInputStream/getOutputStream/getErrorStream.

    However, there's an Apache Commons library called Exec which is designed to make all of this easier. (It can normally get quite hairy when it comes to quoting command line parameters etc.) I haven't used Exec myself, but it's worth checking out.

提交回复
热议问题