错误描述
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上找到如下解决办法:
在Windows 在子进程中使用echo,需要设置 shell =True,因为 echo 不是单独的命令,而是Window CMD 内置的命令
process1 = subprocess.Popen(command1,stdout=subprocess.PIPE,shell=True)
并且,需要注意,只有在绝对需要的情况下才使用shell=True
在lib文件夹中找到subprocess.py
- 搜索
class Popen(object): - 将
__init__中的shell=False修改为shell=True
本文解决了一个在Windows环境下使用Python的selenium库时遇到的子进程错误问题。错误源于尝试启动一个不存在的文件,解决方案是在subprocess.Popen中设置shell=True,并建议仅在必要时使用此参数。此外,文章提供了如何修改subprocess.py中__init__方法的具体步骤。
18万+

被折叠的 条评论
为什么被折叠?



