FileNotFoundError: [WinError 2] 系統找不到指定的文件


用Idle運行Python腳本的時候發現如下錯誤:

Traceback (most recent call last):
  File "D:\Python\Python36-32\lib\site-packages\selenium-3.4.3-py3.6.egg\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "D:\Python\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "D:\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系統找不到指定的文件。

后來在stackoverflow上找到如下解決辦法:

In Windows , to use echo in subprocess, you would need to use shell=True . This is because echo is not a separate executable, but rather a built-in command for the windows command line. Example -
在windows 在子進程中使用echo,需要設置 shell =True,因為 echo 不是單獨的命令,而是window CMD 內置的命令

process1 = subprocess.Popen(command1,stdout=subprocess.PIPE,shell=True)

Also, please do note, you should only use shell=True when absolutely necessary (as in this case , to use echo in windows in subprocess).

並且,需要注意,只有在絕對需要的情況下才使用shell=True

找到 subprocess.py腳本,將對應行加上shell=true 參數。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM