I’m using the subprocess module to start a subprocess (java program) and connect to it’s output stream (stdout). But when i try to get its stdout there is no output.
p= subprocess.Popen(["java -Xmx256m -jar bin/HelloWorld.jar"],cwd=r'/home/karen/sphinx4-1.0beta5-src/sphinx4-1.0beta5/', shell=True, stdout=subprocess.PIPE, bufsize= 4024)
out, err = p.communicate()
print out
I want to be able to execute non-blocking reads on its stdout too.
How can i do both things?
You need to split up the first arg into a list of your args; I think the reason you’re getting no output is that your shell is looking to execute a file named “java -Xmx256m -jar bin/HelloWorld.jar” which clearly isn’t going to exist. You want
["java", "-Xmx256m", "-jar", "bin/HelloWorld.jar"]as the first arg instead, like:Re: wanting to execute non-blocking reads on stdout, see this other answer.