subprocess.Popen('start')失败

时间:2012-02-04 00:26:46

标签: python windows subprocess

在python中运行此操作将导致WindowsError声明无法找到指定的文件

失败:

import subprocess

subprocess.Popen('start notepad.exe')

在命令窗口中,它可以正常工作

start notepad.exe

我猜它是一个路径无法找到的路径开始[.exe?]这个位于何处,所以我可以在路径中添加它或者只是将它包含在Popen调用中。

由于

2 个答案:

答案 0 :(得分:11)

我不完全确定start是一个程序。我认为它可能是CMD shell的内置命令。尝试

subprocess.Popen('cmd /c start notepad.exe')

另外,任何理由都不能仅使用:

subprocess.Popen('notepad.exe')

答案 1 :(得分:0)

notepad = subprocess.Popen(r'start "" "C:\1.txt"', shell=True)
time.sleep(3)
print(notepad.pid)
相关问题