Python 在字典或列表中导出子流程输出结果

Python 在字典或列表中导出子流程输出结果,python,python-2.7,subprocess,Python,Python 2.7,Subprocess,我正在尝试将以下子流程调用的输出放入dict或列表中。然后,我将从中提取一些数据 arg_list = [] action ="QuotaInfo" arg_list.append(upnp_path) arg_list.append(' --action=') arg_list.append(action) arg_list.append(' --ip=') arg_list.append('10.10.8.89') # x = Popen(arg_list, shell=True) o

我正在尝试将以下子流程调用的输出放入dict或列表中。然后,我将从中提取一些数据

arg_list = []
action ="QuotaInfo"
arg_list.append(upnp_path)
arg_list.append(' --action=')
arg_list.append(action)
arg_list.append(' --ip=')
arg_list.append('10.10.8.89')


# x = Popen(arg_list, shell=True)

output = list()

y = subprocess.call(["python", arg_list])
输出

***************Retrieving the QUOTA info for : 10.10.8.89 ***************
INFO::root:Trying main server 10.10.8.40:9000::224
DEBUG::root:Cookies: 'TWISTED_SESSION=988fedac2b7f62cc280c6865f74d9600'::107
containerId  :  3
title  :  pvr
quotaInfoName  :  user
quotaInfoUsedsize  :  17767158
containerRestricted  :  0
quotaInfoMaxsize  :  239221162
class  :  object.container
containerParentid  :  0
INFO::root:Trying main server 10.10.8.40:9000::224
DEBUG::root:Cookies: 'TWISTED_SESSION=988fedac2b7f62cc280c6865f74d9600'::107

我怎样才能做到这一点?谢谢

我刚刚找到了答案

from subprocess import Popen, PIPE, STDOUT



 p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
  output = p.stdout.read()

  print output

我自己刚找到答案

from subprocess import Popen, PIPE, STDOUT



 p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
  output = p.stdout.read()

  print output

你的错误是什么?如果需要输出,应该查看
subprocess.Popen
。Hi@Jean Françoisfab我想将输出保存在dict或list中。我可以在cmd屏幕上获得输出。我的问题是如何将数据传递到dict或列表中?什么的dict?键和值是什么?我需要从输出中获取“quotaInfoUsedsize:17767158”和“quotaInfoMaxsize:239221162”。当您使用call方法时,如果我没有错的话,这不允许您将数据保存在字符串、dict或list中。您的错误是什么?如果需要输出,应该查看
subprocess.Popen
。Hi@Jean Françoisfab我想将输出保存在dict或list中。我可以在cmd屏幕上获得输出。我的问题是如何将数据传递到dict或列表中?什么的dict?键和值是什么?我需要从输出中获取“quotaInfoUsedsize:17767158”和“quotaInfoMaxsize:239221162”。当您使用call方法时,如果我没有错的话,这不允许您将数据保存在string、dict或list中。我将省略stdin=PIPE,因为您没有任何可通过管道传输的内容。不要忘了
p.wait()
等待并获取命令返回code@Jean-弗朗索瓦·法布非常感谢你的帮助,琼。我想省略一下stdin=PIPE,因为你没有任何管道可供使用。不要忘了
p.wait()
等待并获取命令返回code@Jean-弗朗索瓦·法布非常感谢你的帮助,简。