python to get shell command output :
1.
import subprocess
output = subprocess.Popen(['ls','-l'],stdout=subprocess.PIPE,shell=True).commun
icate()
print output[0]
p>
2。
import commands
return_code, output = commands.getstatusoutput('ls -l')
p>
3。
import os
process = os.popen('ls -l') # return file
output = process.read()
process.close()
the original address: http://www.cnblogs.com/snow-backup/p/5035792.html p>
Read More:
- Python packaged *. Exe is running os.popen (cmd)/ subprocess.Popen *. Exe crashes with invalid [winerror 6] handle
- Use subprocess to execute the command line, and the pipeline is blocked
- Python program uses OS. System () method to call exe program, resulting in no response of main program process
- How to Fix Error in python3 | PIP install Dlib
- From in Python__ future__ The role of import *
- Python3 reports an error [errno 5] input / output error. Print is used when there is no stdout
- Python program exit: OS_ Exit() and sys.exit ()
- Error: (2, ‘RegOpenKeyEx’, error resolution
- Ida batch processes virus share samples to obtain ASM files and bytes files
- Pychar console error: xmlrpc.client.Fault : Fault 0: ‘ java.lang.NullPointerException
- In Python sys.argv Usage of
- Python error: command error out with exit status 1:
- Python — magic identify file types
- python keyerror(0)
- Tensorflow in function tf.Print Method of outputting intermediate value
- close failed in file object destructor: IOError: [Error 10] No child processes
- Simple Python crawler exercise: News crawling on sohu.com
- Python: Understanding__ str__
- Windows git review reported an error. UnicodeDecodeError
- Failure [DELETE_ FAILED_ INTERNAL_ After [error], RM APK is unloaded