1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| import subprocess import os def command(command_line): process = subprocess.Popen(command_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() stderr = stderr.decode('utf-8') stdout = stdout.decode('utf-8') print("stdout ",stdout,";stderr ",stderr)
command(['command','arg','aeg'])
def split_str_by_blank(str_com,split_char = ""):
if not split_char:
str_list = str_com.split()
else:
str_list = str_com.split(split_char)
return str_list
def command_print_out_err(str_com):
str_list = split_str_by_blank(str_com)
err , out = commandline(str_list)
if err :
print("ERROR ! : \n",err)
elif out :
print("OUTPUT : \n",out)
|