Comment 12 for bug 445714

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Martin,

Please rest assured I understand very well all of the consequences of using one approach or the other, and opt to use one or the other depending on specific needs. In fact, if you look through the code you'll see that in some cases subprocess was used.

In the case at hand I could very well have avoided it, but the fact that:

 1) it was safe;
 2) it was a one liner;
 3) It is rarely executed; and
 4) I had very little time to implement the system

Guided me towards using this approach.

Also note that it's easy for people to get Subprocess wrong. We should probably implement a wrapper which implements the equivalent of "getstatusoutput()" in a safe way.

In your example above, you actually got it pretty much right. One detail I'd change on it is that you pipe the error output and the standard output into different file descriptors. This means that if the command run outputs error messages interleaved with normal output, the normal output and the error output will be disjoint, and so will be hard to interpret in a log or in the stdout. The proper way would be to use the option stderr=subprocess.STDOUT, so that the error can be observed at the correct places.

Either way, I agree with you, it's a good practice to use subprocess. Let's have more of it.