Reputation: 2062
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>
Upvotes: 0
Views: 1453
Reputation: 5223
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'])
Upvotes: 2