I have a shell script abc.sh
which is called from a Python script custom_package.py
using subprocess.call
function call. I want to return a value from abc.sh
and read it in Python.
Python call to shell script is as follows.
subprocess.call(['abc.sh', user, password])
abc.sh
echos "running" or "not running". How can I capture "running" or "not running" in the Python script? Something like:
ret_val = subprocess.call(['abc.sh', user, password])
I have tried subprocess.check_output
but it's not working.
ret_val = subprocess.check_output(['abc.sh', user, password])
Use subprocess.check_output
to capture the output of a subprocess. If the string 'not'
is not in the returned value, the output was just 'running'
.
output = subprocess.check_output(['abc.sh', user, password])
print(output)
running = 'not' not in output
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.