我需要你的帮助来调试一些东西,我使用Python中的子进程来运行外部应用程序,并使用此命令subprocess.run(["Program", "-o", "-e", "Desktop",new_path])
new_path是一个var,我在其中存储应用程序的路径。所以它看起来很好,但当我用python3 main.py
启动应用程序时,我得到
File "C:\Python27\lib\site-packages\run\__init__.py", line 145, in __new__
process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell)
File "C:\Python27\lib\site-packages\run\__init__.py", line 121, in create_process
shlex.split(command),
File "C:\Python27\lib\shlex.py", line 279, in split
return list(lex)
File "C:\Python27\lib\shlex.py", line 269, in next
token = self.get_token()
File "C:\Python27\lib\shlex.py", line 96, in get_token
raw = self.read_token()
File "C:\Python27\lib\shlex.py", line 124, in read_token
nextchar = self.instream.read(1)
AttributeError: 'list' object has no attribute 'read'
2条答案
按热度按时间rbl8hiat1#
使用
shell=True
运行子进程dkqlctbz2#
在Python 3.5中,
subprocess
内置模块支持run()
将cmds作为列表或字符串。从错误打印
(C:\Python27\lib\site-packages\run\__init__.py)
来看,看起来像是PyPI包的submodule.run()
被调用了,而不是内置包的方法。这个方法不接受cmds作为列表。参考:https://pypi.org/project/subprocess.run/安装PyPI包