how to get output of grep command (Python)
Try that :
import subprocess
hosts = subprocess.check_output("grep 'host:' /root/test.txt", shell=True)
print hosts
Your code should work, are you sure that the user has the access right to read the file?
Also, are you certain there is a "host:"
in the file? You might mean this instead:
hosts_process = subprocess.Popen(['grep','host:',file_input], stdout= subprocess.PIPE)
hosts_out, hosts_err = hosts_process.communicate()