我正在尝试调用应用程序并将文本文件作为参数传递。文本文件有说明。我在打开记事本时尝试传递一个参数,但无法使其工作。这是我正在尝试的代码:
import os
os.startfile(r"C:\Windows\notepad.exe c:\cobra\advancecalendar.txt")
If I don't include the path to the second file it launches notepad, but with the file name included i get the following error:
RESTART: C:/Users/timbo/AppData/Local/Programs/Python/Python36-32/Open exe module.py
Traceback (most recent call last):
File "C:/Users/timbo/AppData/Local/Programs/Python/Python36-32/Open exe module.py", line 3, in <module>
os.startfile(r"C:\Windows\notepad.exe c:\cobra\advancecalendar.txt")
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Windows\\notepad.exe c:\\cobra\\advancecalendar.txt'
如何将参数传递给startfile,以便打开特定文件?当我尝试将两者放在引号中时仍然出现错误。
答案 0 :(得分:1)
使用subprocess
模块。
import subprocess
subprocess.call([r"C:\Windows\notepad.exe", "c:\cobra\advancecalendar.txt"])
在 python2.7
中测试