set the stdin of the process 'grep f' to be 'one\ntwo\nthree\nfour\nfive\nsix\n'
p = subprocess.Popen(['grep', 'f'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
p.stdin.write('one\ntwo\nthree\nfour\nfive\nsix\n')
p.communicate()[0]
p.stdin.close()