python执行shell指令Popen方法

#encoding=utf8
from subprocess import Popen, PIPE, STDOUT
import os

currentPath = os.path.dirname(os.path.realpath(__file__))
command ="echo 'hello linux world!'"
p = Popen(command,shell=True,stdin=PIPE,stdout=PIPE,stderr=STDOUT,close_fds=True,cwd=currentPath)
output, errors = p.communicate()
if errors:
        print(errors)
print(output)

你可能感兴趣的:(linux)