Manidip Sengupta
Manidip Sengupta

Reputation: 3611

Input redirection of child process in Java

I have a program that runs at the shell prompt as

% code arg1 arg2 < inputFile

i.e, gets its input redirected from a file. I need to have this in the form of Runtime().getRuntime().exec ("code arg1 arg2").

How do I get the input redirection? I have tried child.getOutputStream().write(bytes), after reading in the bytes from inputFile, does not work. Any help is appreciated.

Upvotes: 1

Views: 64

Answers (1)

Marko Topolnik
Marko Topolnik

Reputation: 200168

Check out ProcessBuilder, specifically the method redirectInput(File). It gives you what you need out of the box.

Upvotes: 1

Related Questions