推 danqing:加個引號? 03/29 01:30
請問你是說這樣嗎:
import os
exe = r'"C:\Program Files\hfs\hfs.exe"'
param = r'"C:\Program Files\hfs\hfs.vfs"'
os.spawnl(os.P_NOWAIT, exe, param)
出現錯誤耶QQ
Traceback (most recent call last):
File "C:\Program Files\hfs\run.py", line 4, in <module>
os.spawnl(os.P_NOWAIT, exe, param)
File "C:\Program Files\Python26\lib\os.py", line 612, in spawnl
return spawnv(mode, file, args)
OSError: [Errno 22] Invalid argument
推 qwerasdft:"Program Files" 這個呢? 03/29 02:12
→ Holocaust123:param = r'C:\"Program Files"\hfs\hfs.vfs'這樣的話 03/29 02:21
→ Holocaust123:產生一樣的錯誤 03/29 02:21
推 ibmibmibm:param要是list吧:['param1','param2','param3']之類的 03/29 03:42
→ Holocaust123:spawnv(mode,path,args)的args才是list/tuple的樣子. 03/29 11:31
推 doghib:用subprocess.Popen([exe, ]) 03/29 20:18
thx 成功了
參考 Python v2.6.4 documentation 的 18.1.3.4 (Replacing the os.spawn family)
P_NOWAIT example:
pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg")
==> pid = Popen(["/bin/mycmd", "myarg"]).pid
...(下略)
import subprocess
exe = r'C:\Program Files\hfs\hfs.exe'
param = r'C:\Program Files\hfs\hfs.vfs'
subprocess.Popen([exe, param]).pid
※ 編輯: Holocaust123 來自: 140.112.31.144 (03/29 20:44)