I am wondering what the best course of action would be in order to get a java ".jar" file output into a python variable.
For example, let's say a user has a complicated java package (that perhaps the user didn't write and doesn't understand) which they can run in the command window / terminal with
java -jar FileProcessor.jar -i "input.txt" -o "output.txt"
proc = subprocess.Popen(['java', '-jar', 'FileProcessor.jar', '-i', 'sample.txt', '-o'], stdout=subprocess.PIPE)
py_out = proc.stdout.read()
if your program
FileProcessor.jar doesn't have a special case to output to standard output, there's nothing much you can do (but write to a temporary file and read it again, but that's cheating :).
Most nice commands (Unix commands for instance) either dump data to stdout when the
-o option is omitted, or when
-o option has
- value (dash).
Best option is to modify your java program to behave like that.
An alternative on Unix/Linux if you cannot modify your program: