0

How do I go about piping the output of a python program as an argument for a Java program?

I have the following code:

Python (test.py):

print("Hello There")

Java (test.java):

public class Test {
  public static void main(String[] args) {
    for(String value : args) {
      System.out.println(value);
    }
  }
}

In my command line I'm executing the following:

python test.py | java Test

I'm getting the following error:

BrokenPipeError: [Errno 32] Broken pipe

Can anyone explain why this is happening and what would be a good way of fixing it? Many thanks :)

2
  • 2
    Your input is available to be read from System.in, it's not in args. Commented Oct 22, 2020 at 16:16
  • 1
    ...so, from the perspective of the Python program, the pipe on its stdout is broken because the Java program exits without ever reading from the other side of it. Commented Oct 22, 2020 at 16:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.