Skip to content

Instantly share code, notes, and snippets.

@eavidan
Created July 31, 2017 10:23
Show Gist options
  • Save eavidan/8f394230543707d0b358153c5359a84b to your computer and use it in GitHub Desktop.
Save eavidan/8f394230543707d0b358153c5359a84b to your computer and use it in GitHub Desktop.
Easy mining
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