2

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.

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

subprocess.call() doesn't return until the command it runs finishes. You can use multithreading to run something else at the same time.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.