python 执行命令

来源:互联网 发布:淘宝分享有礼在哪里 编辑:程序博客网 时间:2024/06/16 10:04

1、os.system(“cmd”)
2、win32api.ShellExecute(hwnd, op, file, args, dir, show)
3、win32process.CreateProcess(appName, cmdLine, proAttr, threadAttr, InheritHandle, CreationFlags, newEnv, currentDir, Attr)
4、使用ctypes调用kernel32.dll中的函数
5、os.popen()
6、subprocess.call()
7、subprocess.Popen()

另外注意下面,摘抄网上的:
进程
操作系统进程启动及通信库。
envoy – 比 Python subprocess 模块更人性化。
sarge – 另一 种 subprocess 模块的封装。
sh – 一个完备的 subprocess 替代库。

使用心得:
在使用subprocess时。
PyCharm的控制台、python自带的IDLE,和从windows的cmd运行脚本,行为是有差异的,千万要注意。脚本一定要用windows的cmd运行一下。