Get a return value using subprocess

前端 未结 3 1284
醉梦人生
醉梦人生 2020-12-03 13:25

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         


        
相关标签:
3条回答
  • 2020-12-03 14:14

    subprocess.call already returns the process return value. If you're always getting 0, then you'll need to review SCRIPT to make sure that it's returning the value you expect.

    To double check, you can also execute the SCRIPT in a shell and use $? to get the return code.

    0 讨论(0)
  • 2020-12-03 14:19

    Use subprocess.check_output() instead of subprocess.call().

    0 讨论(0)
  • 2020-12-03 14:28

    If your script is returning the value, then you would want to use subprocess.check_output():

    subprocess.check_output([SCRIPT, "-d", date], shell=True).
    

    subprocess.check_call() gets the final return value from the script, and 0 generally means "the script completed successfully".

    0 讨论(0)
提交回复
热议问题