How to run shell script in python

藏色散人
Release: 2019-07-05 10:46:01
Original
9398 people have browsed it

How to run shell script in python

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.

How to run shell script in python

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.

How to run shell script in python

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.

How to run shell script in python

Calling the shell script in python

hello.sh

How to run shell script in python

The following 512 is returned status code, if eixt is 0, it returns 0.

How to run shell script in python

shell script uses the parameters of the python script

Write a hello.sh script, you need Pass in two parameters:

How to run shell script in python

The execution result is as follows:

How to run shell script in python

Call the shell script in the python script and pass Enter the parameters, pay attention to the spaces before and after the parameters

How to run shell script in python

##Execute the python script

How to run shell script in python

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!