简体   繁体   中英

Executing a cmd.exe command from a python script

I have a python script callee.py which is in a certain directory and that directory is part of the Windows PATH environment variable. In the Windows command prompt cmd.exe I can simply execute it as

> callee.py arg1 arg2

Now, I have another python script caller.py in another directory. To execute the first script I would like to use the subprocess module like

subprocess.Popen("callee.py arg1 arg2")

but this does not work, because it does not get that it should actually call python.exe callee.py ... . Furthermore,

subprocess.Popen("python.exe callee.py arg1 arg2")

does not work, because it does not find callee.py .

Is there something like subprocess.Popen which accepts the very same kind of commands that the Windows command prompt cmd.exe does?

Is callee.py executable? Or, why don't you give the full path?

subprocess.Popen("python.exe c:\full_path\to\callee.py arg1 arg2")

Too late, don't consider this answer.

它像这样工作

subprocess.Popen("cmd.exe /c callee.py arg1 arg2")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM