1. Popen使用

test = subprocess.Popen('ls /tmpa', shell=True, stdout = subprocess.PIPE, stderr=subprocess.PIPE)

print test.stdout.read()

print test.stderr.read()

说明: shell=True代表 unix下相当于args前面添加了 "/bin/sh“ ”-c”, window下,相当于添加"cmd.exe /c",

     stdout、stderr输出到PIPE中否则会直接print出来,我们使用Popen就是为了获取这些结果,当然放到PIPE管道中了

PIPE管道是类文件对象,可调用read方法来获得

2.call使用

test = subprocess.call('ls /tmp', shell=True)

print test

说明:call是执行命令,返回的值是执行状态的结果,成功是0.

subprocess使用的更多相关文章

  1. Python subprocess.Popen communicate() 和wait()使用上的区别

    之所以会纠结到这个问题上是因为发现在调用Popen的wait方法之后程序一直没有返回.google发现wait是有可能产生死锁的.为了把这个问题彻底弄清楚,搜索一些资料过来看看: 原文链接:http: ...

  2. Non-blocking read on a subprocess.PIPE in python

    import sys from subprocess import PIPE, Popen from threading import Thread try: from Queue import Qu ...

  3. python学习道路(day7note)(subprocess模块,面向对象)

    1.subprocess模块   因为方法较多我就写在code里面了,后面有注释 #!/usr/bin/env python #_*_coding:utf-8_*_ #linux 上调用python脚 ...

  4. >Python下使用subprocess中文乱码的解决方案

    # -*- coding: CP936 -*- import subprocess cmd="cmd.exe" begin=101 end=110 while begin<e ...

  5. subprocess模块

    subprocess的目的就是启动一个新的进程并且与之通信. subprocess模块中只定义了一个类: Popen.可以使用Popen来创建进程,并与进程进行复杂的交互.它的构造函数如下: subp ...

  6. Python基础篇【第6篇】: Python模块subprocess

    subprocess Python中可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen*          --废弃 popen2.*         ...

  7. python3+ 模块学习 之 subprocess

    subprocess 模块方法: call() check_call() check_output() 以上三个方法用于创建一个子进程,父进程等待子进程结束.若shell = true, 则shell ...

  8. python subprocess阻塞

    import select import os import subprocess import time import fcntl args = ['python','./fetch_file2.p ...

  9. python subprocess.Popen 非阻塞

    1.非阻塞设置subprocess.Popen(args, stdout=subprocess.PIPE,stderr=subprocess.PIPE) def non_block_read(outp ...

  10. python模块之subprocess

    可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen*          --废弃 popen2.*           --废弃 commands.* ...

随机推荐

  1. [ZZ] 景深效果(Depth of Field) , Pass1 将场景渲染到一个RenderTarget,做为清晰版, Pass2: BluredRT , Pass3: WDepth = Depth / Far_Z_Clip

    http://blog.csdn.net/xoyojank/article/details/1883520   什么是景深效果? 景深效果,简称DOF,在人眼跟光学摄像设备上很常见.如下图: 简单地来 ...

  2. PHP-FPM + Nginx: 502错误

    /etc/php5/fpm/pool.d/www.conf 里面找到这样一段代码: listen = 127.0.0.1:9000 在这上面代码的下面添加一行: listen = /var/run/p ...

  3. MySQL解压版安装配置

    官网下载地址:http://dev.mysql.com/downloads/windows/installer/ (可以选择解压版zip下载,也可以选择msi安装版.) 解压zip版配置: 1. 下载 ...

  4. NSQ部署

    一.      简介 NSQ主要有三个主要程序和一个Web服务程序: nsqd:是守护进程,接收,缓存,并投递消息给客户端 nsqlookupd:是一个守护进程,为消费者提供运行时发现服务,来查找指定 ...

  5. js 程序出发事件

    <html> <head><title>Test</title></head> <body> <div id='divTe ...

  6. React.js model

    // tutorial1.js var CommentBox = React.createClass({ render: function() { return ( <div className ...

  7. Jquery元素选取、常用方法;js只能获取内联样式,jquery内联内嵌都可以获取到;字符串.trim();去字符串前后空格

    一:常用的选择器: 基本选择器 $("#myDiv") //匹配唯一的具有此id值的元素 $("div") //匹配指定名称的所有元素 $(".myC ...

  8. C++ 简易时间类

    .h file #ifndef LIBFRAME_DATETIME_H_ #define LIBFRAME_DATETIME_H_ #include <stdint.h> #include ...

  9. [LeetCode]题解(python):110 Balanced Binary Tree

    题目来源 https://leetcode.com/problems/balanced-binary-tree/ Given a binary tree, determine if it is hei ...

  10. jQuery获取自身HTML

    <html><head> <title>jQuery获取自身HTML</title> <meta http-equiv="Content ...