Advertisement
Guest User

Untitled

a guest
May 25th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. import subprocess
  2.  
  3. def execute(cmd):
  4. popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
  5. for stdout_line in iter(popen.stdout.readline, ""):
  6. yield stdout_line
  7. popen.stdout.close()
  8. return_code = popen.wait()
  9. if return_code:
  10. raise subprocess.CalledProcessError(return_code, cmd)
  11.  
  12. # Example
  13. for path in execute(['sudo', 'bash', '/mnt/cephfs/huicheng/dhl-idc/offline-assembly-02.sh']):
  14. print(path, end="")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement