0

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

2

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.