【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 ...
随机推荐
- NetDMA
NetDMA provides operating system support for direct memory access (DMA) offload. TCP/IP uses NetDMA ...
- 纪念逝去的岁月——C++实现一个队列(使用类模板)
1.代码 2.运行结果 1.代码 #include <stdio.h> #include <string.h> template <typename T> clas ...
- 一个不错的安卓下ssh客户端
1.使用安卓作为ssh客户端连接ssh服务器 软件名:JuiceSSH 版本 :1.4.8 大小 :4.22 M 百度网盘地址:JuiceSSH_1.4.8.apk 或 JuiceSSH_1 ...
- Javascript 异步编程的4种方法
你可能知道,Javascript语言的执行环境是"单线程"(single thread). 所谓"单线程",就是指一次只能完成一件任务.如果有多个任务,就必须排 ...
- 已知树的前序、中序,求后序的java实现&已知树的后序、中序,求前序的java实现
public class Order { int findPosInInOrder(String str,String in,int position){ char c = str.charAt(po ...
- Hibernate的第一次测试解析
解析:此题目考查的是对Hibernate中交叉连接的理解.HQL支持SQL风格的交叉连接查询,交叉连接适用于两个类之间没有定义任何关联时.在where字句中,通过属性作为筛选条件,如统计报表数据.使用 ...
- Oracle 部分函数使用说明
oracle有些函数可能我知道是什么作用,但是具体其实说不清楚,这里是我这几天看到的函数使用方法及说明,记录一下,以后看看 --1.replace('str',oldVal,newVal)替换功能方法 ...
- parentNode,offsetParent
元素.parentNode : 父节点 只读 属性 当前节点的父级节点 没有兼容性问题 可放心使用 <!DOCTYPE HTML> <html> <head> ...
- spring security 图解过滤器的使用
1. HttpSessionContextIntegrationFilter 位于过滤器顶端,第一个起作用的过滤器. 用途一,在执行其他过滤器之前,率先判断用户的session中是否已经存在一个Sec ...
- iOS Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:7962
Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Cac ...