1. When the shell script executes the Python script, you need to use the return value of the Python script to determine the command to be executed by the following program
Example: There are two py programs hello.py
Copy Code code as follows:
def main ():
Print "Hello"
If __name__== ' __main__ ':
Main ()
world.py
def main ():
Print "Hello"
If __name__== ' __main__ ':
Main ()
Shell Script test.sh
Copy Code code as follows:
Python hello.py
Python world.py
Perform SH test.sh print results to
Copy Code code as follows:
In hello.py, the shell script is judged by its parameters by the return value,
Hello.py wrote this.
Copy Code code as follows:
Import Sys
def main ():
Try
print "Hello"
Sys.exit (0)
Except
Sys.exit (1)
If __name__== ' __main__ ':
Main ()
The shell script is changed to
Copy Code code as follows:
Python hello.py
if [$?==0];then
Exit
Else
Python world.py
Fi
We can tell.