Print Failure or success based on the value of the standalone tool

Chris Angelico rosuav at gmail.com
Fri May 11 02:46:24 EDT 2018


On Fri, May 11, 2018 at 1:38 PM, Cameron Simpson <cs at cskk.id.au> wrote:
> Returning to system() versus the subprocess module, there are other reasons
> to prefer the subprocess module. The biggest is that os.system() runs a
> shell command, a string passed to the programme /bin/sh. As such, that
> string is subject to all manner of syntax - anything the shell can
> understand.

Another good point about subprocess is that you can capture the OUTPUT
of the called command, not just its return value. Hence it is the
easiest and most obvious solution to the OP's problem - that
os.system() leaves the output going to the screen, and thus cannot
succeed or fail based on it.

ChrisA



More information about the Python-list mailing list