【Python】 Subprocess module
1. subprocess.check_output()
2.subprocess.call()
3. subprocess.check_call()
the methods 1.2.3 are are wrapper of subprocess.Popen()
- example 1:
Open Visual Studio through python
This way is incorrect.
>>> retcode = subprocess.call('devenv.exe', shell=True)
'devenv.exe' is not recognized as an internal or external command,
operable program or batch file.
Another way:
retcode = subprocess.call("C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe",shell=True)
It's done.
Your VS is opened. But the invoke process is blocked. You have to close the process you spawned to get the return code.
- example 2:
try to run iisreset command with python
>>> print subprocess.check_call("iisreset", shell = True)
Attempting stop...
Internet services successfully stopped
Attempting start...
Internet services successfully restarted
0
class Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)
What the Popen returns is a child process you want to create.
example 3:
the Popen() process will not be blocked unless we explicit child.wait()
import subprocess
def havewait():
child = subprocess.Popen(['ping','vwijin014'])
child.wait()
print 'parent process' def nowait():
child = subprocess.Popen(['ping','vwijin014'])
#child.wait()
print 'parent process'
Pay attention to the red line order. One is before the ping running.

【Python】 Subprocess module的更多相关文章
- 【Python②】python之首秀
第一个python程序 再次说明:后面所有代码均为Python 3.3.2版本(运行环境:Windows7)编写. 安装配置好python后,我们先来写第一个python程序.打开IDLE (P ...
- 【Python】 零碎知识积累 II
[Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...
- 【python】列出http://www.cnblogs.com/xiandedanteng中所有博文的标题
代码: # 列出http://www.cnblogs.com/xiandedanteng中所有博文的标题 from bs4 import BeautifulSoup import requests u ...
- 【python】多进程锁multiprocess.Lock
[python]多进程锁multiprocess.Lock 2013-09-13 13:48 11613人阅读 评论(2) 收藏 举报 分类: Python(38) 同步的方法基本与多线程相同. ...
- 【python】SQLAlchemy
来源:廖雪峰 对比:[python]在python中调用mysql 注意连接数据库方式和数据操作方式! 今天发现了个处理数据库的好东西:SQLAlchemy 一般python处理mysql之类的数据库 ...
- 【python】getopt使用
来源:http://blog.chinaunix.net/uid-21566578-id-438233.html 注意对比:[python]argparse模块 作者:limodou版权所有limod ...
- 【Python】如何安装easy_install?
[Python]如何安装easy_install? http://jingyan.baidu.com/article/b907e627e78fe146e7891c25.html easy_instal ...
- 【Python】-NO.97.Note.2.Python -【Python 基本数据类型】
1.0.0 Summary Tittle:[Python]-NO.97.Note.2.Python -[Python 基本数据类型] Style:Python Series:Python Since: ...
- 【Python】-NO.99.Note.4.Python -【Python3 条件语句 循环语句】
1.0.0 Summary Tittle:[Python]-NO.99.Note.4.Python -[Python3 条件语句 循环语句] Style:Python Series:Python Si ...
随机推荐
- 【CodeVS】1204 寻找字串位置
题目描述 Description 给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置. 输入描述 Input Description 仅一行包含两个字符串a和b 输出描述 ...
- 直接用Qt写soap
直接用Qt写soap 最近的项目里用到了webservice, 同事用的是`gSoap`来搞的. 用这个本身没什么问题, 但这货生成的代码实非人类可读, 到处都是`__`和`_`, 看得我眼晕.... ...
- iOS 开发技巧总结
1.添加定时器的常用代码 - (void)delayEnableTabButton { self.tabChannelButton.enabled = NO; [self appendTimer]; ...
- Java_解密ThreadLocal
概述 相信读者在网上也看了很多关于ThreadLocal的资料,很多博客都这样说:ThreadLocal为解决多线程程序的并发问题提供了一种新的思路:ThreadLocal的目的是为了解决多线程访问资 ...
- Oralce中SQL删除重复数据只保留一条(转)
用SQL语句,删除掉重复项只保留一条 在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢 .查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select ...
- REST
REST (REpresentational State Transfer). 为REST模式的Web服务与复杂的SOAP和XML-RPC对比来讲明显的更加简洁. "设计良好的网络应用表现为 ...
- [LintCode] Maximal Rectangle 最大矩形
Given a 2D boolean matrix filled with False and True, find the largest rectangle containing all True ...
- Introduction of Team Member
1. 姓名:xx 性别:男 出生日期:1993.04.16 班级:110616班 职务:小班长 爱好:唱歌.排球 2. 姓名:xxx 性别:男 出生日期:1993.4.20 3. 姓名:xxx 性别: ...
- 关于ueditor1_4_3 上传出现无法加载配置的问题
我的解决方案是: 1. 检查 ueditor.config.js 中的 serverUrl: URL + "/net/controller.ashx" 的配置,记得一定用绝对路径 ...
- HTTP协议 (四) 缓存
HTTP协议 (四) 缓存 阅读目录 缓存的概念 缓存的好处 Fiddler可以方便地查看缓存的header 如何判断缓存新鲜度 通过最后修改时间,判断缓存新鲜度 与缓存相关的header ETag ...