Created
May 23, 2016 21:18
-
-
Save marius92mc/664f006f885b694d8fb5ecb85839789d to your computer and use it in GitHub Desktop.
Content inspired from http://www.cyberciti.biz/faq/python-run-external-command-and-get-output/
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 subprocess | |
def print_shell_command(cmd): | |
## run it ## | |
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE) | |
while True: | |
out = p.stderr.read(1) | |
if out == '' and p.poll() != None: | |
break | |
if out != '': | |
sys.stdout.write(out) | |
sys.stdout.flush() | |
print_shell_command("cd; cd Desktop; ls -lht | grep drw") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment