0
我在这里有一些代码尝试从Python打开cmd.exe
并输入一些命令行以供使用。Python中的子进程模块到cmd.exe
这就是:
PDF= "myPDF"
output= "my output TIF"
def my_subprocess(command,c='C:\here'):
process = subprocess.Popen(command,stdout=subprocess.PIPE,shell=True,cwd=c)
communicate = process.communicate()[0].strip()
my_subprocess('"cmd.exe" && "C:\\here\\myinfamous.bat" && "C:\\my directory and lines telling cmd to do stuff"'+ PDF + " " + output)
当我的脚本的其余部分运行,在命令提示符下甚至不对外开放,人们似乎没有输出或错误的。我的想法是,它甚至没有运行cmd.exe
命令,所以这些代码都没有进入创建最终输出。
有没有我不正确的做法?
谢谢。
的可能的复制[Python的:在Windows上启动新的命令提示符,然后等待它完成/退出](http://stackoverflow.com/questions/11615455/python-start-new-command-prompt-on -windows-and-wait-it-it-finish-exit) – Cripto
[使用python运行windows shell命令]可能的副本(http://stackoverflow.com/questions/14894993/running-windows-shell-commands-with- python) –
为什么你认为你需要'cmd.exe'在这里?它看起来像[XY问题](http://meta.stackexchange.com/a/66378/137096)。你想做什么?你想运行一个bat文件吗?你需要与它互动吗?你想显示一个PDF文件吗?你需要等到pdf文档关闭吗? – jfs