python调用外部命令

os.system("命令加参数")

stream = os.popen("命令和参数")

print subprocess.Popen("echo Hello World", shell=True,stdout=PIPE).stdout.read()

print os.popen("echo Hello World").read()

return_code = subprocess.call("echo Hello World", shell=True)

os模块里也有C语言里fork/exec/spawn 方法,

print subprocess.Popen("echo %s " % user_input, stdout=PIPE).stdout.read()

你可能感兴趣的:(python调用外部命令)