debugging Python中的子进程不允许读

roejwanj  于 2023-10-24  发布在  Python
关注(0)|答案(2)|浏览(112)

我需要你的帮助来调试一些东西,我使用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'
rbl8hiat

rbl8hiat1#

使用shell=True运行子进程

subprocess.run(["Program", "-o", "-e", "Desktop",new_path], shell=True)
dkqlctbz

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包

pip uninstall subprocess.run

相关问题