Best ways to redirect to log from within the batch
Posted: 17 Dec 2014 16:53
So New question. I know that there are a few ways to do this, but I'd like to find an easier way. So far I have the items listed below that I know of, but I would like something simple that I can add to the beginning of the .bat file without too much trouble.
I would like all of the echo, user input, and program output to be redirected to a log file.
These options are not preferred due to reasons listed:
1. redirect when executing .bat file: c:\batch.bat >> c:\batch.log (our customers are too dumb to get that one right)
2. append >>%LogFile% 2>&1 to the end of each line in the batch (annoying to write on 400 lines, and doesn't get the output from external applications named in batch.bat.
3. Surround each method in () and at the end write >>%LogFile% 2>&1 (I tried and the echo only went to the log file and not the terminal. Possibly there is another way?)
4. exec another batch.bat file with the .bat file. (This means sending customers two files and they will F it up)
Any ideas of a way to do this without cluttering the batch (since we will be editing it on the fly for customers) and without requiring a redirect when run (as customers inevitably screw this up).
Ideas, questions, comments?
I would like all of the echo, user input, and program output to be redirected to a log file.
These options are not preferred due to reasons listed:
1. redirect when executing .bat file: c:\batch.bat >> c:\batch.log (our customers are too dumb to get that one right)
2. append >>%LogFile% 2>&1 to the end of each line in the batch (annoying to write on 400 lines, and doesn't get the output from external applications named in batch.bat.
3. Surround each method in () and at the end write >>%LogFile% 2>&1 (I tried and the echo only went to the log file and not the terminal. Possibly there is another way?)
4. exec another batch.bat file with the .bat file. (This means sending customers two files and they will F it up)
Any ideas of a way to do this without cluttering the batch (since we will be editing it on the fly for customers) and without requiring a redirect when run (as customers inevitably screw this up).
Ideas, questions, comments?