Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python subprocess.Popen doesn't take text argument

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?

like image 764
HelloGoodbye Avatar asked Oct 05 '18 10:10

HelloGoodbye


People also ask

How do I use subprocess Popen in Python?

The recommended approach to invoking subprocesses is to use the run() function for all use cases it can handle. For more advanced use cases, the underlying Popen interface can be used directly. Run the command described by args. Wait for command to complete, then return a CompletedProcess instance.

Does subprocess Popen block?

Popen is nonblocking. call and check_call are blocking. You can make the Popen instance block by calling its wait or communicate method.

What is the difference between subprocess run and Popen?

The main difference is that subprocess. run() executes a command and waits for it to finish, while with subprocess. Popen you can continue doing your stuff while the process finishes and then just repeatedly call Popen. communicate() yourself to pass and receive data to your process.

What does subprocess Popen return?

Popen Function The function should return a pointer to a stream that may be used to read from or write to the pipe while also creating a pipe between the calling application and the executed command. Immediately after starting, the Popen function returns data, and it does not wait for the subprocess to finish.


1 Answers

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.

like image 71
Cecile Avatar answered Sep 18 '22 13:09

Cecile