如何在 eclipse 上执行 java 中的 exe 并通过变量传递输入并在控制台上获取输出?
How to execute an exe in java on eclipse and pass intput through a variable and get output on console?
我有一个 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);
}
}
即使我在文件中得到输出,它也会有所帮助。
你可以这样做
for(int i=0;i<1000;i++) {
ProcessBuilder builder = new ProcessBuilder("urcmd","urarg");
builder.redirectOutput(new File("C:\output\process"+i+".txt"));
builder.start();
}
我有一个 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);
}
}
即使我在文件中得到输出,它也会有所帮助。
你可以这样做
for(int i=0;i<1000;i++) {
ProcessBuilder builder = new ProcessBuilder("urcmd","urarg");
builder.redirectOutput(new File("C:\output\process"+i+".txt"));
builder.start();
}