Search code examples
pythonpython-3.xdebuggingsubprocessruntime-error

Subprocess in python don't allow read


i need your help to debug something I use subprocess in python to run an external application with this command

subprocess.run(["Program", "-o", "-e", "Desktop",new_path])

new_path is a var where i store the path of the app. So it's seem's good but when i start the app with python3 main.py i get

 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'

Solution

  • Run the subprocess with shell=True

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