469,358 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

how to retrieve output from makefile build

When building using a makefile, is there a way to retrieve all the output build generated by the make file. Because when i build with a cmd window, all the output of the build shows in the cmd window. But when using the same command in python, it seems that I can't retrieve all the build info. It does build properly but the information I am trying to retrieve is not there. I am using the os.popen function but it is not working well.

My code is:
os.chdir("c:\\ProjectDir")
CmdLine = "makel"
RetBuild = os.popen(CmdLine)
sys.stdout.flush()

# lets find out if the build was a success with no error.
for Line in RetBuild:
# lets write in a log file the return of the build.
fpLog.write(Line)
Mar 13 '07 #1
7 2233
bartonc
6,596 Expert 4TB
When building using a makefile, is there a way to retrieve all the output build generated by the make file. Because when i build with a cmd window, all the output of the build shows in the cmd window. But when using the same command in python, it seems that I can't retrieve all the build info. It does build properly but the information I am trying to retrieve is not there. I am using the os.popen function but it is not working well.

My code is:
Expand|Select|Wrap|Line Numbers
  1.         os.chdir("c:\\ProjectDir")
  2.         CmdLine = "makel"
  3.         RetBuild = os.popen(CmdLine)
  4.         sys.stdout.flush()
  5.  
  6.         # lets find out if the build was a success with no error.        
  7.         for Line in RetBuild:  
  8.             # lets write in a log file the return of the build.
  9.             fpLog.write(Line)
1st: code tags work here, spaces don't.
2nd:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. logFile = open('fpLog', 'w')
  3. sys.stdout = logFile
  4.  
  5. # do your build
  6.  
  7. logFile.close()
might do the trick.
Mar 13 '07 #2
1st: code tags work here, spaces don't.
2nd:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. logFile = open('fpLog', 'w')
  3. sys.stdout = logFile
  4.  
  5. # do your build
  6.  
  7. logFile.close()
might do the trick.

Sorry, I forgot to mention that fpLog is from a class i built. So bassically, fpLog.write(Line) write a line in a file. This has no problem, and also I do build using different tools such with visual C++ using the msdev and I do retrieve all the build information. But with the make, I can't retrieve all the build information that I do see when building using directly the command line in a Cmd Window.
Mar 13 '07 #3
dshimer
136 Expert 100+
If you are trying to trap the output of a command to a list of lines try
Expand|Select|Wrap|Line Numbers
  1. RetBuild = os.popen(CmdLine).read().split('\n')
Mar 13 '07 #4
If you are trying to trap the output of a command to a list of lines try
Expand|Select|Wrap|Line Numbers
  1. RetBuild = os.popen(CmdLine).read().split('\n')

One other point is I do retrieve some little information from the build such as this line

(C) Copyright OPUS Software 1987-91. All rights reserved.

This line is probably the compiler header. So I can retrieve this line with no problem in my log file. But the information I am looking is a line at the end of the build to see if the build was successfull such as the following line: Output.out is up to date
This line can only be seen in the Cmd window. But I just can't retrieve it in my file. And I know that I am going through all the lines of the output build since I do build other project using other tools such as Visual Studio, and I can retrieve all the output line with no problem. But with the make file, the os.popen function output only a few lines.
Mar 13 '07 #5
When using the os.system command, I see all of the proper output in my cmd window. It is as if the os.system and os.popen are not returning the same thing
Mar 13 '07 #6
dshimer
136 Expert 100+
When using the os.system command, I see all of the proper output in my cmd window. It is as if the os.system and os.popen are not returning the same thing
Without regard to stdout, and the log file, if you just run
Expand|Select|Wrap|Line Numbers
  1.  RetBuild = os.popen(CmdLine).read().split('\n')
from inside your ide, or python for that matter, does the list stored in RetBuild contain all the information? I'm just trying to establish that there isn't a second issue because I have used this code quite a bit and it generally returns exactly what I'd expect.
Mar 14 '07 #7
Without regard to stdout, and the log file, if you just run
Expand|Select|Wrap|Line Numbers
  1.  RetBuild = os.popen(CmdLine).read().split('\n')
from inside your ide, or python for that matter, does the list stored in RetBuild contain all the information? I'm just trying to establish that there isn't a second issue because I have used this code quite a bit and it generally returns exactly what I'd expect.
Exactly, that is my problem, the popen function, does not return everthing I am expecting. I did try the following but it did only return a couple of lines.

Expand|Select|Wrap|Line Numbers
  1.  RetBuild = os.popen(CmdLine).read().split('\n')
I am not seing the result of the built.
Mar 14 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Gg | last post: by
4 posts views Thread by newbiecpp | last post: by
4 posts views Thread by Sharp Tool | last post: by
5 posts views Thread by Jacobo Rodriguez Villar | last post: by
4 posts views Thread by Jess | last post: by
8 posts views Thread by xz | last post: by
7 posts views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
14 posts views Thread by Anna Smidt | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.