I have an input file test.txt as:
host:dc2000
host:192.168.178.2
I want to get all of addresses of those machines by using:
grep "host:" /root/test.txt
And so on, I get command ouput via python:
import subprocess
file_input='/root/test.txt'
hosts=subprocess.Popen(['grep','"host:"',file_input], stdout= subprocess.PIPE)
print hosts.stdout.read()
But the result is empty string.
I don't know what problem I got. Can you suggest me how to solve?
Try that :
import subprocess
hosts = subprocess.check_output("grep 'host:' /root/test.txt", shell=True)
print hosts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With