subprocess.Popen('start')失败

Bre*_*ett 3 python windows subprocess

在python中运行它将导致WindowsError声明它找不到指定的文件

失败:

import subprocess

subprocess.Popen('start notepad.exe')
Run Code Online (Sandbox Code Playgroud)

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

start notepad.exe
Run Code Online (Sandbox Code Playgroud)

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

谢谢

mil*_*ose 11

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

subprocess.Popen('cmd /c start notepad.exe')
Run Code Online (Sandbox Code Playgroud)

此外,任何原因不使用只是:

subprocess.Popen('notepad.exe')
Run Code Online (Sandbox Code Playgroud)

  • 另外,`subprocess.Popen('start notepad.exe',shell = True)`应该可以工作. (8认同)