Last active
January 10, 2020 05:33
-
-
Save bugcy013/42d507dc0e5d4a88cfa6d3fbd2b58348 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import subprocess | |
| def run_cmd(cmd="hostname", work_dir=None): | |
| try: | |
| logging.critical("let's execute cmd=%s", cmd) | |
| pipe = subprocess.Popen(cmd, shell=True, cwd=work_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| out, error = pipe.communicate() | |
| print(out, error) | |
| pipe.wait() | |
| except: | |
| import traceback | |
| print(traceback.print_exc()) | |
| if __name__ == '__main__': | |
| run_cmd("ls -ltr") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment