Shubham Verma
Shubham Verma

Reputation: 139

How to execute an exe in java on eclipse and pass intput through a variable and get output on console?

I have an exe file and i want to execute it for a large number of times passing a variable as an input and print the output for each case..

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);
    }
}

Even if i get the output in a file it will be helpful.

Upvotes: 1

Views: 74

Answers (1)

Arkantos
Arkantos

Reputation: 6608

You can do something like this

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

Upvotes: 3

Related Questions