python execute external command and get output

Use the subprocess library

import subprocess
out_bytes = subprocess.check_output(['netstat','-a'])

out_bytes = subprocess.check_output('grep python j wc > out', shell=True)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325870640&siteId=291194637