import subprocess
import sys
def run_shell(shell):
"""use python execute ubuntu's command
Args:
shell (str): command for ubuntu
Returns:
int: returncode
during this executation , it will print the system's log
"""
cmd = subprocess.Popen(shell, stdin=subprocess.PIPE, stderr=sys.stderr,
close_fds=True, stdout=sys.stdout, universal_newlines=True, shell=True, bufsize=1)
cmd.communicate()
return cmd.returncode
调用方式
runshell("pwd")
效果