Computer Hope
Microsoft => Microsoft DOS => Topic started by: dbreienrk1 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.
-
What do you mean by the "results"? Do you mean the console outputs of the python scripts?
-
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.
-
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 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.
-
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?
-
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.