I try simple code using subprocess on python, while calling process.stdout.readline() it will hang on it. How to solve this problem? While trying fcntl for nonblock in the output I got blank output.
my source code:
from subprocess import Popen,PIPE
import fcntl
import os
proc = Popen(['./test'],stdin=PIPE,stdout=PIPE)
fcntl.fcntl(proc.stdout.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
print "Started!"
print proc.stdout.readline()
proc.stdin.write('5\n')
proc.stdin.flush()
print proc.stdout.readline()
proc.stdin.write('5\n')
proc.stdin.flush()
print proc.stdout.readline()
proc.stdout.close()
proc.stdin.close()
The output should be like this:
First number: 5
Second number: 5
Answer: 10