Can this be somehow overcome? Can a child process create a subprocess?
The problem is, I have a ready application which needs to call a Python script. This script on its own works perfectly, but it needs to call existing shell scripts.
Schematically the problem is in the following code:
import subprocess
subprocess.call(['/usr/sfw/bin/python', '/usr/apps/openet/bmsystest/relAuto/variousSW/child.py','1', '2'])
import sys
import subprocess
print sys.argv[0]
print sys.argv[1]
subprocess.call(['ls -l'], shell=True)
exit
python child.py 1 2
all is ok
python parent.py
Traceback (most recent call last):
File "/usr/apps/openet/bmsystest/relAuto/variousSW/child.py", line 2, in ?
import subprocess
ImportError: No module named subprocess
Subprocess in Python is a module used to run new codes and applications by creating new processes. It lets you start new applications right from the Python program you are currently writing. So, if you want to run external programs from a git repository or codes from C or C++ programs, you can use subprocess in Python.
The subprocess. check_output() is used to get the output of the calling program in python. It has 5 arguments; args, stdin, stderr, shell, universal_newlines. The args argument holds the commands that are to be passed as a string.
The subprocess module defines one class, Popen and a few wrapper functions that use that class. The constructor for Popen takes arguments to set up the new process so the parent can communicate with it via pipes. It provides all of the functionality of the other modules and functions it replaces, and more.
There should be nothing stopping you from using subprocess in both child.py and parent.py
I am able to run it perfectly fine. :)
Issue Debugging:
You are using
python
and/usr/sfw/bin/python
.
I am sure if you did the following, it will work for you.
/usr/sfw/bin/python parent.py
Alternatively, Can you change your parent.py code
to
import subprocess
subprocess.call(['python', '/usr/apps/openet/bmsystest/relAuto/variousSW/child.py','1', '2'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With