Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a return value using subprocess [duplicate]

Tags:

People also ask

How do I get output from subprocess?

To get a string as output, use “output. stdout. decode(“utf-8”)” method. You can also supply “text=True” as an extra argument to the subprocess.

What does subprocess return in Python?

The Python subprocess call() function returns the executed code of the program. If there is no program output, the function will return the code that it executed successfully. It may also raise a CalledProcessError exception.


I want to be able to define a variable by the return value of a script. This is what I currently have:

sum_total_earnings_usd = subprocess.call([SCRIPT, "-d", date]) 

I have checked the return value of SCRIPT, however, when I try and set this variable, it always returns 0 ( http://docs.python.org/library/subprocess.html#subprocess.call ). How would I run this script and capture the return value to store as a variable?