我想将下面的shell求值转换为python2.6(无法升级)。我不知道如何评估命令的输出。你知道吗
以下是shell版本:
status=`$hastatus -sum |grep $hostname |grep Grp| awk '{print $6}'`
if [ $status != "ONLINE" ]; then
exit 1
fi
我尝试了os.popen
,它返回['ONLINE\n']。你知道吗
value = os.popen("hastatus -sum |grep `hostname` |grep Grp| awk '{print $6}'".readlines()
print value
尝试子流程模块:
文档可在此处找到: https://docs.python.org/2.6/library/subprocess.html?highlight=subprocess#module-subprocess
建议使用subprocess模块。
文档的以下部分具有指导意义:
replacing shell pipeline
我在此报告以供参考:
变成:
变成:
下面是要翻译的菜谱欧斯波本到子流程模块:
replacing os.popen()
所以你可以这样做
或者
连接Popens,如上面的文档所示(可能我会这么做)。你知道吗
然后,为了测试您可以使用的输出,假设您使用的是第一种方法:
相关问题 更多 >
编程相关推荐