How to run shell script in python?
system()
The last 0 is the return value of this command. If it is 0, it means the command execution is successful. The execution results cannot be saved using system.
popen()
Get the result of command execution, but there is no execution status of the command. In this way, the obtained result can be saved and placed in the list.
commands
You can easily obtain the output of the command (including standard and error output) and execution status bits.
commands.getoutput('ls') This method only returns the execution result result and does not return status.
Calling the shell script in python
hello.sh
The following 512 is returned status code, if eixt is 0, it returns 0.
shell script uses the parameters of the python script
Write a hello.sh script, you need Pass in two parameters:
The execution result is as follows:
Call the shell script in the python script and pass Enter the parameters, pay attention to the spaces before and after the parameters
##Execute the python script Related recommendations: "Python Tutorial》
The above is the detailed content of How to run shell script in python. For more information, please follow other related articles on the PHP Chinese website!