By some need I was forced to correct os.environ['PATH'] to be able to run dir\to\fake\python.cmd script which adds some extra parameters to the original one before execution.
Also I have two python scripts:
test1.py:
# ...
p = subprocess.call("test2.py") # shell=True works fine
# ...
test2.py:
# ...
print "Hello from test2.py"
# ...
When I run python test1.py my "fake" python.cmd doing its stuff, refers to the original python in c:\Python25 and runs test1.py with my extra arguments. But, sadly, test2.py, script is never called. If I put shell=True as subprocess.call argument - everythin's fine, test2.py is called.
I know, Windows is trying to find python interpreter to use for the call in the real c:\Python25 working directory when shell=False is by default.
The question to you is: how can I achieve the goal without changing my code in test1.py and test2.py? Maybe virtualenv library may be very useful in this case?
Thank you very much for your help
subprocess.call("test2.py")work if you runtest1.pywith the original python? Is your wrapper called if you runsubprocess.call("test2.py", shell=True)? What are file associations for*.pyfiles on your machine? Do you want to run all python files usingpython.cmd? Why can't you changetest1.pycode to includeshell=True, what are disadvantages ofshell=Truein this case?subprocess.call()to call a python script? Justimport test2in totest1and use threading or multiprocess to dispatch a child worker if needed, or just call it directly if it all operates sequentially anyway. You are already in python code, why go back out to the OS to run other python code?