Module Summary of Python invoke shell command

Source: Internet
Author: User
Tags stdin

Os.system (' Cat/proc/cpuinfo ')

block, returns the state of the shell Execution parameter command, which successfully returns 0

Os.popen (' Cat/proc/cpuinfo ')

block, returns the object of file read, and the read () of the object can get the result of the shell Execution parameter command, which is the standard output

Commands.getstatus ('/proc/cputinfo ')

block, returns the detailed properties of the system file specified by the parameter

Commands.getoutput (' Cat/proc/cpuinfo ')

block, returns the result of the shell execution parameter command

Commands.getstatusoutput (' Cat/proc/cpuinfo ')

block, return the shell status and shell output tuple (status, output)

Subprocess.call (args, *, Stdin=none, Stdout=none, Stderr=none, Shell=false)

block, return to shell status, disable PIPE parameters

Subprocess.check_call (args, *, Stdin=none, Stdout=none, Stderr=none, Shell=false)

Blocked, shell execution successfully returns 0, otherwise no return, and throws a Calledprocesserror exception that contains the shell error state, disables the pipe parameter

Subprocess.check_output (args, *, Stdin=none, Stderr=none, Shell=false, Universal_newlines=false)

Blocked, shell execution successfully returns the shell result, otherwise no return, and throws a Calledprocesserror exception that contains the shell error state, disables the pipe parameter

Subprocess. Popen (args, bufsize=0, Executable=none, Stdin=none, Stdout=none, Stderr=none, Preexec_fn=none, Close_fds=false, shell= False, Cwd=none, Env=none, Universal_newlines=false, Startupinfo=none, creationflags=0)

Do not block, return Popen object

Subprocess Parameters:

Args: String or list (the first item under *nix is treated as a command, followed by a command parameter)

BufSize: Default 0 unbuffered, 1 rows buffered, other positive numbers indicate buffer size, negative indicates using system default full buffering

stdin stdout stderr:subprocess. Pipe represents pipeline operation, subprocess. STDOUT indicates output to standard output

Preexec_fn:*nix called before the process is executed

Shell:true indicates that the specified command is interpreted in the shell for execution.

Subprocess. Pipe: For stdin, stdout, and stderr, which means creating and writing a pipeline

Subprocess. STDOUT: For stderr, indicates standard error redirection to standard output

Popen Object Properties:

Popen.poll () Checks if the child process is over, 0 indicates exit

Popen.wait () Waits for the child process to end, noting that the child process is writing the pipeline

Popen.communicate (Input=none) interacts with the child process, the string data is sent to stdin, and the data is read from stdout and stderr, knowing EOF, waiting for the child process to end. Note that the pipe parameters are given when reading stdin, stdout, or stderr. Returns the tuple (Stdoutdata, stderrdata).

Popen.send_signal (signal) sends a signal to the child process

Popen.terminate () Stop child process

Popen.kill () Kill child process

Popen.stdin popen.stdout Popen.stderr Pipe parameter is a file object, otherwise none

Process number of the POPEN.PID child process

Popen.returncode None indicates that the child process is not terminated, negative-n indicates that the child process is terminated by the n signal





Module Summary of Python invoke shell command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.