Issue 891832: commands module doesn't support background commands (original) (raw)

The structure of the command passed to os.popen() prevents the getoutput() and getstatusoutput() functions from accepting commands for background execution. I think it would be sufficient to see if the last non-whitespace character in the command was '&' and if so, suppress insertion of the semicolon into the command passed to os.popen():

dosemi = not cmd.strip()[-1:] == '&' pipe = os.popen('{ %s%s } 2>&1' % (cmd, dosemi and ';' or ''), 'r')

The above is untested, but based on my fiddling at the shell prompt seems to be what's called for.

Since the status and output mean little or nothing when the command is executed in the background, perhaps a better alternative would be to add a new function to the module which doesn't return either, but dumps stdout and stderr to /dev/null.