2
我已經閱讀無處不在,子進程模塊是從Python使用命令行的最佳方式,但是我無法使其工作。我有一個名爲Page Saver的Firefox擴展,它保存了整個網頁的圖像。在COMAND線,此命令成功保存的圖像:在Python中執行Firefox命令
firefox -savepng "http://www.google.com"
我試過這個腳本來自動生成的過程,但沒有運氣:
import subprocess
subprocess.call(['firefox', '-savepng', 'http://www.google.com'], shell=False)
我得到這個錯誤:
Traceback (most recent call last):
File "C:/Users/computer_4/Desktop/Scripts/crescentsaver.py", line 2, in <module>
subprocess.call(['firefox', '-savepng', 'http://www.google.com'], shell=False)
File "C:\Python27\lib\subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
我是否正確使用子流程? 謝謝。
更新: 找到解決方案。這是我使用的擴展的一點細節。該腳本必須從Firefox的默認保存文件夾中運行才能正常工作。我也跑了參數字符串,而不是一個列表,殼=真:
import subprocess
subprocess.call('firefox -savepng http://www.google.com', shell=True)
我不能回答我的問題,由於對新用戶8小時張貼的內回答自己的問題的限制。