I'm a new bie to python programming and programming as well. so kindly excuse if this sound to be a basic question.
I'm developing a tool which on course performs make clean and make on git.
I'm using subprocess module for running these make commands.
One observation is: I use communicate to see the results of the make commands. the issue with communicate is, it waits for the subprocess.popen to finish and then sends the output.
if the make command runs for 30 mins, there is no output on the screen for 30 mins and then communicate sends the entire data what it had collected for the 30 mins.
Question is: Is there a way to get the output from the subprocess as and when there is something displayed on stdout and then print it out on the screen?
The code that I had written so far is:
def makeClean(path,cmd1='make',cmd2='clean'):
print '+++++++++++ RUNNING MAKE CLEAN +++++++++++ \n'
c = subprocess.Popen([cmd1 , cmd2],stdout = subprocess.PIPE, stderr = subprocess.PIPE,cwd = path)
out = c.communicate()[0]
for line in out.split('\r\n'): print line
Any thoughts on this? I tried using pexpect.run() but that did not work for me...
-Vijay