I am trying to run 3 python programs simultaneously by running a single python program
I am using the following script in a separate python program sample.py
Sample.py:
import subprocess
subprocess.Popen(['AppFlatRent.py'])
subprocess.Popen(['AppForSale.py'])
subprocess.Popen(['LandForSale.py'])
All the three programs including python.py is in the same folder.
Error: OSError: [Errno 2] No such file or directory
Can someone guide me how can i do it using subprocess.Popen method?
The file cannot be found because the current working directory has not been set properly. Use the argument
cwd="/path/to/script"
in PopenThere might be shebang missing (
#!..
) in some of the scripts or executable permission is not set (chmod +x
).You could provide Python executable explicitly:
The above assumes that script names are given relative to the module.
Consider importing the modules and running corresponding functions concurently using
threading
,multiprocessing
modules instead of running them as scripts directly.It's because your script are not in the current directory when you execute sample.py. If you three script are in the same directory than sample.py, you could use :
But honestly, if i was you i will do it using a bash script.