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?
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 toexec()the python process, open and read thexyz.txtfile with Java, then send the data to the exec’d process’ standard in (You can get that stream from theProcessobject).