准备一个exe小程序(我的小程序下载链接https://download.youkuaiyun.com/download/qq_43036122/10969837),java开发环境,我们使用的是Process类java的进程管理类,需要使用里面的方法,process.getInputStream();在网上看了好多,讲的好复杂,自己写了一个例子,拿来既可以使用,超级简单,有什么问题请留言
我准备的exe小程序是只能执行一分钟,然后会输出一个hello,最终结果就是打印到控制台,使用java程序去获取结果
直接上例子(结果如图)
package test;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class AppOutputCapture {
//先创建一个新的空线程
private static Process process=null;
public static void main(String[] args) throws IOException {
getValue();
} // main()
public static String getValue() throws IOException{
Runtime mt =Runtime.getRuntime();
File myfile =new File("d:\\b","ru.exe");
String path =myfile.getAbsolutePath();
String[] cmd = {path};
try {