-3

I have a java program that i run with the following command

java -jar <program_name>.jar --<some_parameter> <some_filename>.csv

Within my python script I create the <some_filename>.csv. Then, I would like to execute the java program and use the program's stdout output in my python script.

Is there an easy way to do so?

Joe
  • 1

2 Answers2

1

Try with subprocess:

import subprocess
result = subprocess.run([COMMAND LIST], stdout=subprocess.PIPE)
print(result.stdout)

[COMMAND LIST] is a string list of the words in the command separated by space

Wasif
  • 13,656
  • 3
  • 11
  • 30
0

Try with this:

import subprocess

p = subprocess.Popen(["java", "-jar <program_name>.jar --<some_parameter> <some_filename>.csv"],shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if not out:
   print(err.rstrip().decode())
else:
   print(out.rstrip().decode())
Clown Down
  • 482
  • 2
  • 6
  • 18