Python执行DOS命令以及处理url

来源:互联网 发布:道教有什么软件 编辑:程序博客网 时间:2024/06/06 05:40
#function:Python执行DOS命令#brif:1,2,3个方法可用于执行程序和打开文件,方法4可以处理浏览url#author:xyang#1、os.system(cmd)import oscmd = 'cmd.exe /k net user'#/k表示执行完命令后不关闭shell窗口os.system(cmd)#2、os.popen(cmd)x = os.popen("cmd.exe /k net user").read()print x#3、class subprocess.Popen(cmd,shell=True)import subprocesssubprocess.Popen("cmd.exe /k net user")#4、webbrowser.open(url)import webbrowserwebbrowser.open('http://www.google.com')#会调用默认浏览器打开该url