似乎subprocess.call函数仅可用于扩展名为'.exe'的文件。
[这是我为Firefox.lnk尝试的代码,其中与我为扩展名为'.exe'且没有错误的git程序尝试的代码相同。
import subprocess
subprocess.call('C:/users/m.m/Desktop/Programs/Firefox')
这是我Firefox.lnk
遇到的错误:
Traceback (most recent call last):
File "C:/Users/m.m/PycharmProjects/untitled5/pros.py", line 2, in <module>
subprocess.call('C:/users/m.m/Desktop/Programs/Firefox.lnk')
File
"C:\Users\m.m\AppData\Local\Programs\Python\Python37\lib\subprocess.py",
line 323, in call
with Popen(*popenargs, **kwargs) as p:
File
"C:\Users\m.m\AppData\Local\Programs\Python\Python37\lib\subprocess.py",
line 775, in __init__
restore_signals, start_new_session)
File
"C:\Users\m.m\AppData\Local\Programs\Python\Python37\lib\subprocess.py",
line 1178, in _execute_child
startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application
Firefox
(无扩展名)给我FileNotFoundError: [WinError 2] The system cannot find the file specified
。
[当我为那些扩展名为.exe的程序尝试不带扩展名的代码时,我没有问题,但是对于任何扩展名为'.exe'的程序,我都报错了……就像具有'.lnk'扩展名的Firefox一样。] >
似乎subprocess.call函数只能用于扩展名为'.exe'的文件。这是我为Firefox.lnk尝试的代码,其中与我为具有'....
要在Windows上处理.lnk
文件,标准库中有os.startfile()
(仅Windows)。