如何使用Popen在Windows中打开程序

发布于 2025-02-11 19:05:01 字数 780 浏览 2 评论 0原文

我正在研究一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昇り龍 2025-02-18 19:05:01

从函数popen中删除open参数参数在Python 3:

import subprocess
subprocess.Popen(['C:\\Windows\\System32\\calc.exe'])

另外,您可以使用call()而不是popen( ),结果相同:

subprocess.call(['C:\\Windows\\System32\\calc.exe'])

Removing open parameter argument from the function Popen works well in Python 3:

import subprocess
subprocess.Popen(['C:\\Windows\\System32\\calc.exe'])

Also, you can use call() instead of Popen(), with the same result:

subprocess.call(['C:\\Windows\\System32\\calc.exe'])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文