I am running a subprocess
with the following arguments,
process = subprocess.Popen("myApp", stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
myApp is an CommandLine application.
and to interact with myApp,
response = self.process.communicate(message)[0]
As known, communicate
replies the whole output from myApp rather than only the output after my input.
So i tried the below,
process.stdin.write(message)
response = self.process.stdout.readline()
This prints only the first line.
Currently i have a for loop which will iterate over readline
and append it to a list and process it further to get only the content which i want.
But, what is the correct way to do this? How can i read the output which comes only after my input? Is there any easier way to do it other than looping and processing?
Note: My CommandLine application runs in a loop it takes an input gives output and waits for next input.