Advanced languages can also invoke system commands, sometimes with unexpected output language types python php c 1. There are three common methods of executing system commands in Python python: Os.system os.popen Using Module subprocess
The former return value is the script's exit status code, both of which require an OS module (import OS) (1) Os.system
When the command is executed, the running state is displayed in the window, and the return value is the status code
Import OS
a=os.system (' ping ')
print a
A for the return value 0 represents the success 1 represents the small problem 2 represents the big problem
(2) Os.popen
Its return value is a file object, and you can perform related operations on this file object.
Import OS
a=os.popen (' ping ')
print a.read ()
A is a file object, you can call the object's Read method and the Close method for related operations (3) using module subprocess (child processes)
Import subprocess
a=subprocess. Popen (' ping ', shell=true)
The shell is set to true and the program is executed through the shell. Popen.poll (): Used to check whether the child process has ended. Sets and returns the ReturnCode property. Popen.wait (): Wait for child process to end. Sets and returns the ReturnCode property.
2. PHPShell_exec exec
(1) shell_exec
Gets all output values that the command performs
<?php
$f =shell_exec (' Ipconfig/all ');
echo $f;
? >
Output All information (2) EXEC
Gets the output value of the last command
<?php
$f =exec (' Ipconfig/all ');
echo $f;
? >
Only the last row of 3 is output . C
Header file for include "Stdlib.h"
int main ()
{
System ("ping");
}