Exec_Cmd_Utils.py 606 B

12345678910111213141516171819202122
  1. import subprocess
  2. from V1.PrintLog import printlog
  3. def exeCommonCmd(cmd, cd=None):
  4. try:
  5. s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=cd,encoding='utf-8')
  6. std_output, error_output = s.communicate()
  7. ret = s.returncode
  8. if ret:
  9. printlog("cmd: %s \nexec Fail!" % cmd)
  10. else:
  11. printlog("cmd: %s \nexec Success!" % cmd)
  12. printlog(std_output)
  13. printlog(error_output)
  14. except Exception as e:
  15. print(e)
  16. return 1, e
  17. return ret, std_output