执行外部程序 [英] Execute external program

查看:33
本文介绍了执行外部程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作一个调用外部程序的应用程序,我必须传递两个参数.它不会给出任何错误.

I tried to make an application that calls an external program that I have to pass two parameters. It doesn't give any errors.

program.exe,用C++编写,拍照并修改.txt文件的内容.

The program.exe, written in C++, takes a picture and modifies the content of a .txt file.

Java 程序运行但它什么也不做-

The Java program runs but it does nothing-

这是我的示例代码:

    String[] params = new String [3];
    params[0] = "C:\Users\user\Desktop\program.exe";
    params[1] = "C:\Users\user\Desktop\images.jpg";
    params[2] = "C:\Users\user\Desktop\images2.txt";
    Runtime.getRuntime().exec(params);

推荐答案

这里

Process process = new ProcessBuilder("C:\PathToExe\MyExe.exe","param1","param2").start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;

System.out.printf("Output of running %s is:", Arrays.toString(args));

while ((line = br.readLine()) != null) {
  System.out.println(line);
}

更多信息这里

关于如何传递命令的其他问题这里这里

Other issues on how to pass commands here and here

这篇关于执行外部程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆