使用子进程获取返回值 [英] Get a return value using subprocess

查看:31
本文介绍了使用子进程获取返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够通过脚本的返回值定义一个变量.这是我目前拥有的:

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])

我已经检查了 SCRIPT 的返回值,但是,当我尝试设置这个变量时,它总是返回 0 ( http://docs.python.org/library/subprocess.html#subprocess.call).我将如何运行此脚本并捕获返回值以存储为变量?

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?

推荐答案

使用 <代码>subprocess.check_output() 而不是 subprocess.call().

这篇关于使用子进程获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆