Created
July 31, 2017 10:23
-
-
Save eavidan/8f394230543707d0b358153c5359a84b to your computer and use it in GitHub Desktop.
Easy mining
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 | |
# simply running a command and getting the output | |
cmd = ['ps', '-ax'] | |
s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
(stdoutdata, stderrdata) = s.communicate() | |
#print(stdoutdata) | |
# you can chain commands | |
# the following runs 'ls /etc | grep ntp' by sending the 'ls etc' output to the input of the 'grep ntp' | |
# you can do this as much as you want | |
grep = subprocess.Popen(['grep', 'ntp'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
ls = subprocess.Popen(['ls', 'etc'], stdout=grep.stdin) | |
output = grep.communicate()[0] | |
print(output) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment