how to retrieve output from makefile build

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slalande50
    New Member
    • Feb 2007
    • 11

    #1

    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:\\P rojectDir")
    CmdLine = "makel"
    RetBuild = os.popen(CmdLin e)
    sys.stdout.flus h()

    # 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(Lin e)
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by slalande50
    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:
    Code:
            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)
    1st: code tags work here, spaces don't.
    2nd:
    Code:
    import sys
    logFile = open('fpLog', 'w')
    sys.stdout = logFile
    
    # do your build
    
    logFile.close()
    might do the trick.

    Comment

    • slalande50
      New Member
      • Feb 2007
      • 11

      #3
      Originally posted by bartonc
      1st: code tags work here, spaces don't.
      2nd:
      Code:
      import sys
      logFile = open('fpLog', 'w')
      sys.stdout = logFile
      
      # do your build
      
      logFile.close()
      might do the trick.

      Sorry, I forgot to mention that fpLog is from a class i built. So bassically, fpLog.write(Lin e) 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.

      Comment

      • dshimer
        Recognized Expert New Member
        • Dec 2006
        • 136

        #4
        If you are trying to trap the output of a command to a list of lines try
        Code:
        RetBuild = os.popen(CmdLine).read().split('\n')

        Comment

        • slalande50
          New Member
          • Feb 2007
          • 11

          #5
          Originally posted by dshimer
          If you are trying to trap the output of a command to a list of lines try
          Code:
          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.

          Comment

          • slalande50
            New Member
            • Feb 2007
            • 11

            #6
            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

            Comment

            • dshimer
              Recognized Expert New Member
              • Dec 2006
              • 136

              #7
              Originally posted by slalande50
              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
              Code:
               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.

              Comment

              • slalande50
                New Member
                • Feb 2007
                • 11

                #8
                Originally posted by dshimer
                Without regard to stdout, and the log file, if you just run
                Code:
                 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.

                Code:
                 RetBuild = os.popen(CmdLine).read().split('\n')
                I am not seing the result of the built.

                Comment

                Working...