Return Value of OS. System () in Python

Source: Internet
Author: User

Add: if a third partyProgramThe return value is a Boolean value. OS. system converts true to 1, false to 0, and returns the result.

The forwarding is as follows:

I remember a friend on the python.cn email list asked me about the abnormal return value of OS. System. I met it again today, so let's summarize it.
Problem:
/Bin/xxx. py is a program with a return code of 1.
When the python program uses OS. system (". /bin/xxx. in this way, the OS. the returned value of system becomes 256, that is, 0 × 100. Instead of returning 1 normally.
Solution:
Found the document
OS. System () returns:
On UNIX, the return value is the exit status of the process encoded in
The format specified for wait ().
OS. Wait () returns the following:
A 16-bit number, whose low byte is the signal number that killed
Process, and whose high byte is the exit status (if the signal number
Is zero );
The return value of OS. system is not the result returned by the execution program. It is a 16-bit number, and its high position is the return code. That is to say, OS. System () returns 256, that is, 0 × 0100, And the return code should be its high position 0 × 01, that is, 1.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.