python 中的子进程不允许读取
Subprocess in python don't allow read
我需要你的帮助来调试一些东西
我在 python 中使用子进程到 运行 带有此命令的外部应用程序
subprocess.run(["Program", "-o", "-e", "Desktop",new_path])
new_path 是一个变量,我在其中存储应用程序的路径。所以它看起来很好但是当我用 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'
运行 带有 shell=True
的子进程
subprocess.run(["Program", "-o", "-e", "Desktop",new_path], shell=True)
我需要你的帮助来调试一些东西 我在 python 中使用子进程到 运行 带有此命令的外部应用程序
subprocess.run(["Program", "-o", "-e", "Desktop",new_path])
new_path 是一个变量,我在其中存储应用程序的路径。所以它看起来很好但是当我用 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'
运行 带有 shell=True
subprocess.run(["Program", "-o", "-e", "Desktop",new_path], shell=True)