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:
- The python version output from the command line is inconsistent with the python version in the current CONDA environment
- An undetermined call to function ‘shell’: missing ‘. Stop. Problem encountered when using shell command in makefile
- Error encountered while executing PIP install: error: complete output from command Python setup.py egg_ info:
- After editing a file with the VIM command in xshell, the ESC key cannot be output,,,
- Nohup command in Linux: nohup: assigning input and attaching output to‘ nohup.out ’
- Linux’s method of clearing DNS cache and refreshing DNS in shell terminal (Ubuntu, Debian)
- Python – [encoding] in Python os.system Solution to Chinese garbled code when calling CMD command
- how to clear screen in python shell
- The list command in HBase shell reported an error org.apache.hadoop . hbase.PleaseHoldException : Master is initializing
- Method of modifying file and folder permission by Chmod command in Linux
- Python program uses OS. System () method to call exe program, resulting in no response of main program process
- If elif writing method of shell script
- Error BC: command not found when git bash runs shell script
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3
- An error occurs when HBase uses the shell command: pleaseholdexception: Master is initializing solution
- Error handling method of “no module named ‘stringio’” in Python 3
- Method of ignoring case in Python string comparison
- Shell script running error bash: JPS: command not found
- When executing shell script, $’r ‘: command not found appears
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3