Reputation: 5392
I have a python script calling a java file with the subprocess
module:
import subprocess
java_cmd = ['java', '-cp', 'bin/stuff/:lib/asm-all-3.3.jar:lib/jdom.jar',
'ch.idsia.scenarios.Main']
subprocess.call(java_cmd, shell=False)
print "Hello world"
This works correctly, and the java file then waits for the python script to continue and connect a socket, as I want it to. But the python script doesn't continue. Why not? I know it doesn't because the print
statement never executes.
Everything runs as expected when I manually run the java file from Eclipse and then execute the python script from the command line.
I also tried with subprocess.Popen()
instead of subprocess.call()
, with no difference in the outcome.
Upvotes: 2
Views: 2983
Reputation: 5392
Thank you @KSFT; subprocess.call()
doesn't return until the command finishes, but subprocess.Popen()
does. So I made the call with subprocess.Popen()
and then time.sleep(0.5)
. Having the python script wait 0.5 seconds allows the java file enough time to open and initialize the socket connections.
Upvotes: 3
Reputation: 1774
subprocess.call()
doesn't return until the command it runs finishes. You can use multithreading to run something else at the same time.
Upvotes: 1