如何使用Popen在Windows中打开程序
我正在研究一个Python项目,以打开Windows的应用程序。以下程序如预期的那样编写
import subprocess
subprocess.Popen(['open','C:\\Windows\\System32\\calc.exe'])
: 计算器应用应该打开。
实际的:
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
PS C:\Users\EvanGertis\development\PythonAutomation\Module9>
I am working on a Python project to open an application in Windows. The following program is written like so
import subprocess
subprocess.Popen(['open','C:\\Windows\\System32\\calc.exe'])
Expected:
The calculator app should open.
Actual:
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
PS C:\Users\EvanGertis\development\PythonAutomation\Module9>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从函数
popen
中删除open
参数参数在Python 3:另外,您可以使用
call()
而不是popen( )
,结果相同:Removing
open
parameter argument from the functionPopen
works well in Python 3:Also, you can use
call()
instead ofPopen()
, with the same result: