Python3 invoke shell commands commonly used method

Built-related modules and functions can execute shell commands are:

the os.system
os.spawn
os.popen,
 - waste
popen2 * -. obsolete
commands * -. abandoned, is removed in 3.x

subprocess: tend to substitute os.system, os.spawn *

https://docs.python.org/3/library/subprocess.html?highlight=subprocess

= SH " LS -la "          # shell commands 
# Val = os.system (SH) # os.system received only program execution results to digital int type to return a result, 1 indicates a successful execution 
# Val = os.popen (SH) # os.popen () is obtained in the print function main output 
# Vals = '/n'.join (val.readlines ()) # os.popen, read () is the result of the readlines () or read ( ) 
# All output status and output status of the console (status, output) = subprocess.getstatusoutput ( sh) # obtain a shell command 
# status: indicates the program execution result, the value 0 indicates a successful execution. 
# The Output: is printed to the console with a \ n to a string splicing.

 

Guess you like

Origin www.cnblogs.com/xl717/p/11858641.html