0

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])
5
  • Did you mistype "abc.sh" when you ran check_output()? That's what you're showing in your question. Commented Nov 12, 2014 at 0:09
  • @LukeYeager : was a type in question.fixed it in question. Commented Nov 12, 2014 at 0:11
  • there is no error ,just the return value is blank. I ran the shell script on terminal is producing output. Commented Nov 12, 2014 at 0:12
  • The code in the question is exactly how i have used check_output. Commented Nov 12, 2014 at 0:19
  • oops.sorry ..added it in question. Commented Nov 12, 2014 at 0:22

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.