I would like to run a python command within Java.
The format of the command is as follows:
python abc.py TAG < xyz.txt
When I use Java's Process:
Process p=Runtime.getRuntime().exec("python abc.py TAG < xyz.txt");
I get an incorrect argument error because the < xyz.txt is being interpreted as arguments to abc.py as opposed to the terminal meaning of piping xyz.txt.
Is there any way to run a java command that has the piping functionality?
1 Answer 1
exec() does not involve a shell. You can't do things like that.
You either need to exec() a shell and have it run the python process as you're trying, or you need to exec() the python process, open and read the xyz.txt file with Java, then send the data to the exec'd process' standard in (You can get that stream from the Process object).