popen

The command executed by os.system is print, and the return value is 0 or 1

>>> a=os.system('ls')
usage
0
>>>
>>> a    # a's return value is command status 
0
 >>>

os.popen can save the return value

>>> a=os.popen('df -h')
>>> 
>>> a.read()
'Filesystem      Size  Used Avail Use% Mounted on\nudev            918M     0  918M   0% /dev\ntmpfs           188M   20M  168M  11% /run\n/dev/vda1        50G  2.4G   45G   6% /\ntmpfs           937M   24K  937M   1% /dev/shm\ntmpfs           5.0M     0  5.0M   0% /run/lock\ntmpfs           937M     0  937M   0% /sys/fs/cgroup\ntmpfs           188M     0  188M   0% /run/user/1000\n'
>>> 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324552423&siteId=291194637