subprocess使用
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使用的更多相关文章
- Python subprocess.Popen communicate() 和wait()使用上的区别
之所以会纠结到这个问题上是因为发现在调用Popen的wait方法之后程序一直没有返回.google发现wait是有可能产生死锁的.为了把这个问题彻底弄清楚,搜索一些资料过来看看: 原文链接:http: ...
- 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 ...
- python学习道路(day7note)(subprocess模块,面向对象)
1.subprocess模块 因为方法较多我就写在code里面了,后面有注释 #!/usr/bin/env python #_*_coding:utf-8_*_ #linux 上调用python脚 ...
- >Python下使用subprocess中文乱码的解决方案
# -*- coding: CP936 -*- import subprocess cmd="cmd.exe" begin=101 end=110 while begin<e ...
- subprocess模块
subprocess的目的就是启动一个新的进程并且与之通信. subprocess模块中只定义了一个类: Popen.可以使用Popen来创建进程,并与进程进行复杂的交互.它的构造函数如下: subp ...
- Python基础篇【第6篇】: Python模块subprocess
subprocess Python中可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen* --废弃 popen2.* ...
- python3+ 模块学习 之 subprocess
subprocess 模块方法: call() check_call() check_output() 以上三个方法用于创建一个子进程,父进程等待子进程结束.若shell = true, 则shell ...
- python subprocess阻塞
import select import os import subprocess import time import fcntl args = ['python','./fetch_file2.p ...
- python subprocess.Popen 非阻塞
1.非阻塞设置subprocess.Popen(args, stdout=subprocess.PIPE,stderr=subprocess.PIPE) def non_block_read(outp ...
- python模块之subprocess
可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen* --废弃 popen2.* --废弃 commands.* ...
随机推荐
- 2016.04.27,英语,《Vocabulary Builder》Unit 19
bio, comes from the Greek word for 'life'. biosphere ['baɪoʊsfɪr] n. 生物圈: biology [baɪ'ɑːlədʒi] n. 生 ...
- [读书笔记]Mindset
开始读 Mindset.准备开始记录读书笔记. Question: I know a lot of workaholics on the fast track who seem to have a f ...
- 采用HSV生成随机颜色
使用hsv/hsb生成随机颜色,并排除靠近黑白两色的色值 public static String randomColor(){ int max = 25500000 ; Random rand = ...
- lambda表达式对比
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- 从StackOverflow来的值得回味的编程观点
从StackOverflow来的值得回味的编程观点 很多有意思的话语 在 2012年06月08日 那天写的 已经有 4148 次阅读了 感谢 参考或原文 www.csdn.net 服务器君 ...
- Nginx return 关键字配置小技巧
Nginx的return关键字属于HttpRewriteModule模块: 语法:return http状态码 默认值:无 上下文:server,location,if 该指令将结束执行直接返回htt ...
- 切记CMYK图片格式在IE中将无法显示
目前为止微软的Internet Explorer 浏览器IE6,IE7,IE8都不支持CMYK颜色模式图像 ,除IE外其他浏览器均能支持!所以大家要注意了 要选择RGB颜色模式,就可以了.
- Linux学习之CentOS(十)--虚拟机下的CentOS如何上网
原地址:http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/05/3001148.html 这篇随笔应该说跟CentOS的学习关系不是很大, ...
- MongoDB常用操作总结
====================================MGDB的操作====================================== 0.创建数据库时使用(use 数据库 ...
- Maximal Square || LeetCode
dp. #define MAX 1000 int rowLeft[MAX][MAX]; int colUp[MAX][MAX]; int dp[MAX][MAX]; void calRow(char ...