当前位置: 动力学知识库 > 问答 > 编程问答 >

windows - 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.

网友答案:

It works like this

subprocess.Popen("cmd.exe /c callee.py arg1 arg2")
分享给朋友:
您可能感兴趣的文章:
随机阅读: