subprocess.getstatusoutput does not exist in 2.7

Cecil Westerhof Cecil at decebal.nl
Tue May 19 15:07:13 EDT 2015


Op Tuesday 19 May 2015 19:37 CEST schreef Jon Ribbens:

> On 2015-05-19, Cecil Westerhof <Cecil at decebal.nl> wrote:
>> At the moment I want my code to run with 2.7 and 3.4+.
>>
>> But the command: subprocess.getstatusoutput does not exist in 2.7.
>> Is this an oversight or is there a reason for it?
>>
>> I can rewrite the code (back) to work with Popen again, but I found
>> the getstatusoutput elegant.
>
> It's in the 'commands' module in Python 2. You could use the
> following:
>
> try:
> from subprocess import getstatusoutput
> except ImportError:
> from commands import getstatusoutput

Works like a charm. Thanks.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof



More information about the Python-list mailing list