Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File Output to Log file  (Read 16663 times)

0 Members and 1 Guest are viewing this topic.

dbreienrk1

    Topic Starter


    Greenhorn

    Batch File Output to Log file
    « on: December 02, 2008, 11:04:16 AM »
    I am working with python scripting to expedite some basic processes utilized in ESRI ArcInfo. I have a list of 200+ python scripts that I put into a .bat file to process overnight (which works fine), but I want to output the results of each into a single logfile. Anyone know how to do this? The .bat file looks like this.

    D:\CreateFileGDB1.py
    D:\CreateFileGDB2.py
    D:\CreateFIleGDB3.py

    I just want the results of each in a .txt file after they are all done. Thanks.
    I feel sorry for people who don't drink. When they wake up in the morning, that's as good as they're going to feel all day.

    - Sinatra -

    Dias de verano

    • Guest
    Re: Batch File Output to Log file
    « Reply #1 on: December 02, 2008, 11:20:12 AM »
    What do you mean by the "results"? Do you mean the console outputs of the python scripts?

    dbreienrk1

      Topic Starter


      Greenhorn

      Re: Batch File Output to Log file
      « Reply #2 on: December 02, 2008, 11:30:37 AM »
      Yes, I want what DOS outputs to be appended to a single .txt file.  I already tried the > and >> redirect operators.  It creates the .txt file, but nothing is appended to it.
      I feel sorry for people who don't drink. When they wake up in the morning, that's as good as they're going to feel all day.

      - Sinatra -

      dbreienrk1

        Topic Starter


        Greenhorn

        Re: Batch File Output to Log file
        « Reply #3 on: December 02, 2008, 11:41:24 AM »
        Hopefully this will explain what I want to be written to the .txt file better.  Here is an example for when I run the .bat and what the cmd prompt outputs...

        *************************
        C:\CreateFileGDB1.py
        Error File Already Exists

        C:\CreateFileGDB2.py

        C:\CreateFileGDB3.py

        C:\CreateFileGDB4.py
        Error File Already Exists
        *************************

        The python scripts run as they are designed.  2 & 3 run properly. 1 & 4 error due to the file already existing (which I intentionally created so I can verify it is logging errors).  I just want all of what the .cmd outputs to be saved to a .txt.
        I feel sorry for people who don't drink. When they wake up in the morning, that's as good as they're going to feel all day.

        - Sinatra -

        Dias de verano

        • Guest
        Re: Batch File Output to Log file
        « Reply #4 on: December 02, 2008, 11:46:22 AM »
        I think your problem may be that error messages go to stderr and not stdout so you need to capture the stderr output

        batchfile.bat > file.txt 2>&1

        Google for stderr and stdout to see squillions of explanations.





        dbreienrk1

          Topic Starter


          Greenhorn

          Re: Batch File Output to Log file
          « Reply #5 on: December 02, 2008, 12:08:00 PM »
          Thank you very much man.  That worked.  Now a one more question (and if it's too much to explain don't worry about it) but what does the "2>&1" command mean?
          I feel sorry for people who don't drink. When they wake up in the morning, that's as good as they're going to feel all day.

          - Sinatra -

          Dias de verano

          • Guest
          Re: Batch File Output to Log file
          « Reply #6 on: December 02, 2008, 01:01:25 PM »
          Both in Unix and also in Windows (NT and later, not 9x), console programs and scripts can write to two different output streams. They are called stdout and stderr. Normally (i.e. without any redirection) they both output to the screen. When you use the > and >> redirection symbols on their own (without a number 1 or 2 before them) you are redirecting just the stdout stream. Most programs use the stdout for their normal output and the stderr for their error messages.

          If you want to make sure you only capture one of these streams you can put a number 1 (stdout) or a 2 (stderr) in front of the redirection symbols

          program 1> output.txt 2> error.txt

          by putting 2>&1 after the file name you combine the two streams.