0

I have an exe file, say Factorial.exe.

When i run it, it takes n and computes n!. It is not possible to change the program to pass n as a command line argument.

I know how to run this using ProcessBuilder, but I don't know how to give input to it. I think one of the options would be using redirection, so we have :

Factorial.exe < input.txt 

which there is a single number in input.txt.

But I can't simply call

ProcessBuilder builder = new ProcessBuilder("Factorial.exe < input.txt");

or

ProcessBuilder builder = new ProcessBuilder("Factorial.exe"," < input.txt");

as the input of ProcessBuilder.


I found a way to do this, But i can't call it an answer its just a way to do it. I create the input.txt file , with the appropriate input. I call a batch file using ProcessBuilder with this command : Factorial.exe < input.txt

this makes it work and i'm gonna use it, but i'm still curious to know is there any better way.

Vahid
  • 1,265
  • 10
  • 20
  • Something like this? http://stackoverflow.com/questions/1431551/command-line-pipe-input-in-java – ehoberg Jan 23 '15 at 10:49
  • no, in that question, the user is giving the input file to a java program. i want to give input file to an exe file using java – Vahid Jan 23 '15 at 11:37

1 Answers1

0

Just add the parameter to the ProcessBuilder-Constructor:

new ProcessBuilder("Factorial.exe","5").start();
Steffen
  • 341
  • 1
  • 12