3 ms·
The portion that explains of how subprocess shuns dev/ops guys in the beginning is so true. Perl/Bash colleagues at work would basically ask me how to perform o
by joshbaptiste 15y ago
The portion that explains of how subprocess shuns dev/ops guys in the beginning is so true. Perl/Bash colleagues at work would basically ask me how to perform output=`command`. Once they seen subprocess, they would continue writing their script in Bash/Perl.
- bobbyi 15y agoIf backticks are good enough for them, then they don't need the more complex usecases that Popen allows, so just tell them to use check_call or check_output. As far as they should be concerned, the subprocess module has two functions that are straightforward to use. And those functions are more convenient than the default behavior of backticks, because they handle for you raising an exception if the subprocess fails. Python: import subprocess output = subprocess.check_output('command') Perl: $output = `command` die "failed: $output" if $?
- brendano 15y agoVery true. I spent quite a while trying to learn subprocess, then gave up and just use os.popen() now. It's a shame -- there are certain subprocess features I really would like to have, but it's too hard to remember how to use it.
- dagw 15y agoI used subprocess in a program as recently as this afternoon and I'm quite baffled about the amount of negativity it attracts. Sure it's not quite as simple as `ls -l` but it's not too far off and in return it gives you far more control. Is there anything in particular that you found hard or confusing?
- codejoust 15y agoI've done a considerable amount of work in subprocess. It's API isn't amazing, but it does have quite a few great features and once you spend a little time with it really isn't too bad. Some of the piping features, along with shell arguments work quite well.
- d0mine 15y agofrom subprocess import check_output as qx output = qx(['command', 'arg1'])
- pnathan 15y agoIf you commit to building an infrastructure library, you can make a very nice and powerful interface into subprocess that makes life much easier.