related question में, मैंने पूछा कि सी फ़ंक्शन "प्रतीक्षा" के लिए प्रलेखन कहां ढूंढें। यह command.getstatusoutput() मॉड्यूल के लिए रिटर्न कोड को समझने का प्रयास था। Stackoverflow के माध्यम से आया, लेकिन दस्तावेज मदद नहीं की।पायथन कमांड में स्थिति कोड की व्याख्या कैसे करें .getstatusoutput()
#!/usr/bin/python
import commands
goodcommand = 'ls /'
badcommand = 'ls /fail'
status, output = commands.getstatusoutput(goodcommand)
print('Good command reported status of %s' % status)
status, output = commands.getstatusoutput(badcommand)
print('Bad command reported status of %s' % status)
जब पर ओएस एक्स (तेंदुआ) चलाने मैं निम्नलिखित उत्पादन प्राप्त: (। कौन सा प्रलेखन से मेल खाता है)
$ python waitest.py
Good command reported status of 0
Bad command reported status of 256
OS X पर, कर एक "ls/असफल यहाँ क्या पहेली मुझे है ; echo $? "
$ ls /fail ; echo $?
ls: /fail: No such file or directory
1
जब लिनक्स (Ubuntu Hardy) पर चलाने के मैं निम्नलिखित उत्पादन हो:
$ python waitest.py
Good command reported status of 0
Bad command reported status of 512
उबंटू पर, कर "ls/असफल" हो जाता है एक 2:
$ ls /fail ; echo $?
ls: cannot access /fail: No such file or directory
2
निम्नलिखित उत्पादन हो जाता है
तो पाइथन 256 तक स्टेटस कोड गुणा कर रहा है। हू? क्या यह कहीं दस्तावेज है?
[@Schof द्वारा जवाब] होना चाहिए (http://stackoverflow.com/a/1535675/52074) सवाल का जवाब "का उपयोग करते समय' command.getstatusoutput() '256 तक एक्जिटकोड गुणा क्यों हैं? " सीधे और उदाहरण कोड के साथ। अन्य दो उत्तरों में कम से कम 'कमांड'getstatusoutput() '" या "subprocess का उपयोग करने के तरीके" के बजाय "subprocess' का उपयोग करें" कहें। –