*** Spam *** Re: commands.getstatusoutput result is not command line exit value!!!
Steve Holden
steve at holdenweb.com
Mon Oct 2 11:44:49 EDT 2006
A famous Holden typo - it should have been "12 * 256 == 3072", but
really it shouldn't have been beyond you to perform a division of 3072
by 12 (given that you already knew the number 12 was potentially involved).
Basically the value you want is shifted up 8 bits. Perhaps I should more
understandably have said:
12 << 8 == 3072
regards
Steve
Hari Sekhon wrote:
> I don't quite understand what you are saying here:
>
> 2 * 256 is 512,
> 2 ** 256 is some extremely large number.
>
> 2**12 is 4096.
>
> So how does 3072 factor into this?
>
> Could you explain what you mean by "the error in the top half of a
> sixteen-bit value"?
>
> This makes no sense to me at this moment.
>
> -h
>
> Hari Sekhon
>
>
>
> Steve Holden wrote:
>
>>Hari Sekhon wrote:
>>
>>
>>>I'm running a command like
>>>
>>>import commands
>>>result = commands.getstatusoutput('somecommand')
>>>print result[0]
>>>3072
>>>
>>>
>>>However, this exit code made no sense so I ran it manually from the
>>>command line in bash on my linux server and it gives the exit code as
>>>12, not this weird 3072 number.
>>>
>>>So I tried os.system('somecommand') in the interactive python shell and
>>>it too returned the same result for the exit code as the unix shell, 12,
>>>but re-running the commands.getstatusoutput() with the exact same
>>>command still gave 3072.
>>>
>>>
>>>Is commands.getstatusoutput() broken or something?
>>>
>>>
>>>-h
>>>
>>>
>>>
>>No, it's just returning the error code in the top half of a sixteen-bit
>>value. You will notice that 3072 == 2 * 256.
>>
>>That's always been the way the Unix return code has been returned
>>programattically, but the shell shifts it down to make it more usab;e.
>>
>>regards
>> Steve
>>
>>
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list