Error in executing .jar file from a Python script called from another Python script, as a subprocess

219 Views Asked by At

This is in extension to a resolved post that I had posted here. I have a python script which has the following jar execution code in it(alongwith some other codes):

python_file2.py

import os
cmd_txt = "ssh -i pem_file.pem user@" + host_name + " 'cd /user/folder1/ && java -cp jar-file.jar'"
os.system(cmd_txt)

Now this python script file(python_file2.py) is called as a subprocess from another python script.

Main_script.py

ret = subprocess.Popen([sys.executable,"python_file2.py"])

When I run this Main_script.py then the execution of the jar file from python_file2.py seems to get hanged. When I run the first script alone it works fine but when I try to execute it as subprocess then the jar execution hangs and timeouts.

What could be a possible reason for this jar execution getting hanged when executed from inside a subprocess script? All I want to is run a jar file which is present on remote machine from inside a python script which is ran as a subprocess.

1

There are 1 best solutions below

3
On

Use subprocess.call instead of subprocess.Popen:

ret = subprocess.call([sys.executable,"python_file2.py"])
assert not ret, ret