Reputation: 3902
According to the Python 3 documentation for subprocess.Popen, the class constructor takes an optional argument text
(which is supposed to control whether the file objects stdin, stdout and stderr are opened in text mode).
However, when I try setting text=true
upon construction of a Popen
object, I get the error
Failed: TypeError: __init__() got an unexpected keyword argument 'text'
and when I look in the source code (I'm using Python 3.6.4), the constructor takes no argument text
. What is going on here? Why does the documentation say the constructor takes an optional argument text
when it doesn't in the version of subprocess.py
that I have?
Upvotes: 15
Views: 20289
Reputation: 6736
As @Cecile said, some parameters like text
and capture_output
have been added in 3.7.
So in order to run some commands in it you can try the following code:
import subprocess
subprocess.run('git --version', shell=True, check=True, universal_newlines=False)
If you want to capture the output (capture_output) in version 3.6 try the following:
from subprocess import PIPE
import subprocess
subprocess.run('git --version', shell=True, check=True, universal_newlines=False, stdout=PIPE, stderr=PIPE)
P.S. For more information, you can checkout this link.
Upvotes: 1
Reputation: 1745
I have the feeling the text parameter has been added in 3.7, not 3.6.
Relevant part of the doc:
Changed in version 3.7: Added the text parameter, as a more understandable alias of universal_newlines. Added the capture_output parameter.
Upvotes: 32