Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在eclipse上用java执行exe,并通过变量传递intput,然后在控制台上获得输出?_Java_Execution - Fatal编程技术网

如何在eclipse上用java执行exe,并通过变量传递intput,然后在控制台上获得输出?

如何在eclipse上用java执行exe,并通过变量传递intput,然后在控制台上获得输出?,java,execution,Java,Execution,我有一个exe文件,我想执行它很多次,传递一个变量作为输入,并打印每种情况下的输出 Runtime runtime = Runtime.getRuntime(); for(int i=0;i<1000;i++) { Process p = runtime.exec("cmd /c start C:/Users/sbm/workspace/Codex/a.exe",i); BufferedReader input = new BufferedReader(new Inpu

我有一个exe文件,我想执行它很多次,传递一个变量作为输入,并打印每种情况下的输出

Runtime runtime = Runtime.getRuntime();

for(int i=0;i<1000;i++)
{
    Process p = runtime.exec("cmd /c start C:/Users/sbm/workspace/Codex/a.exe",i);

    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));

    String line;

    while ((line = input.readLine()) != null)
    {
        System.out.println(line);
    }
}
Runtime=Runtime.getRuntime();

对于(inti=0;i你可以这样做

for(int i=0;i<1000;i++) {
   ProcessBuilder builder = new ProcessBuilder("urcmd","urarg");
   builder.redirectOutput(new File("C:\\output\\process"+i+".txt"));
   builder.start();
}

for(int i=0;如果上述解决方案解决了您的问题,请接受此答案。当然,在正确测试之后:-)