<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[运维进行时]]></title> 
<link>https://blog.liuts.com/index.php</link> 
<description><![CDATA[互联网运维与架构]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[运维进行时]]></copyright>
<item>
<link>https://blog.liuts.com/post//</link>
<title><![CDATA[python执行外部命令或URL]]></title> 
<author>root &lt;admin@yourname.com&gt;</author>
<category><![CDATA[Python]]></category>
<pubDate>Sat, 22 Sep 2007 07:10:43 +0000</pubDate> 
<guid>https://blog.liuts.com/post//</guid> 
<description>
<![CDATA[ 
	在Python/wxPython环境下，执行外部命令或者说在Python程序中启动另一个程序的方法一般有这么几个：<br/>1、os.system(command)<br/>2、wx.Execute(command, syn=wx.EXEC_ASYNC, callback=None)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;若置syn为wx.EXEC_ASYNC则wx.Excute函数立即返回，若syn=wx.EXEC_SYNC则等待调用的程序结束后再返回。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;callback是一个wx.Process变量，如果callback不为None且syn=wx.EXEC_ASYNC，则程序结束后将调用wx.Process.OnTerminate()函数。<br/>os.system()和wx.Execute()都利用系统的shell，执行时会出现shell窗口。如在Windows下会弹出控制台窗口，不美观。下面的两种方法则没有这个缺点。<br/>3、class subprocess.Popen<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;最简单的用法是：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;import subprocess<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subprocess.Popen(command, shell=True)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果command不是一个可执行文件，shell=True不可省。<br/>前面三个方法只能用于执行程序和打开文件，不能处理URL，打开URL地址可用webbrowser模块提供的功能。<br/>4、webbrowser.open(url)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;调用系统缺省浏览器打开URL地址，如 webbrowser.open('http://www.google.com')，也可以利用<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webbrowser.open('h:&#92;python.zip')来执行程序。这样可以不必区分是文件名还是URL，不知道在Linux下是否可行。<br/>以上在Windows2000，Python2.4a1，wxPython 2.5.1运行。<br/>modify:还有一种方式：subprocess.call(*args, **kwargs)<br/>Tags - <a href="https://blog.liuts.com/tags/%25E5%25A4%2596%25E9%2583%25A8%25E5%2591%25BD%25E4%25BB%25A4/" rel="tag">外部命令</a>
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post//#blogcomment</link>
<title><![CDATA[[评论] python执行外部命令或URL]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://blog.liuts.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>