python 捕获shell脚本的输出结果实例

yipeiwu_com6年前Python基础

import subprocess
output =Popen(["mycmd","myarg"], stdout=PIPE).communicate()[0]


import subprocess
p = subprocess.Popen(['ls','-a'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print out

 

# work on Unix/Linux only

import commands
print commands.getstatusoutput('wc -l file')[1]

以上就是小编为大家带来的python 捕获shell脚本的输出结果实例全部内容了,希望大家多多支持【听图阁-专注于Python设计】~

相关文章

在Python 中同一个类两个函数间变量的调用方法

在Python 中同一个类两个函数间变量的调用方法

如下所示: class A(): def test_a(self): self.m ="hello" def test_b(self): self.test...

python 给DataFrame增加index行名和columns列名的实现方法

python 给DataFrame增加index行名和columns列名的实现方法

在工作中遇到需要对DataFrame加上列名和行名,不然会报错 开始的数据是这样的 需要的格式是这样的: 其实,需要做的就是添加行名和列名,下面开始操作下。 # a是Data...

Python变量访问权限控制详解

Python变量访问权限控制详解

oop1.py文件代码 # user/bin/python class Foo: def bar(self): print('ok') def hello(self, name):...

numpy中的高维数组转置实例

numpy中的高维数组转置实例

numpy中的ndarray很适合数组运算 transpose是用来转置的一个函数,很容易让人困惑,其实它是对矩阵索引顺序的一次调整。原先矩阵是一个三维矩阵,索引顺序是x,y,z,角标...

python 默认参数相关知识详解

最常见的一种形式是的是为一个或者多个参数指定默认值,这会创建一个可以使用比定义时允许的参数更少的参数调用的函数, def ask_ok(prompt, retries=4, remi...