Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am looking to redirect output from a batch file
to BOTH the screen and a file.
Currently I use "doit.bat > test.txt",
but don't get the screen output.Robert...

... and you won't.
Batch files themselves can't be redirected, only commands (and not all of them). Possibly, you could redirect a command's output on a line IN the BAT file.

Currently I use "doit.bat > test.txt",
ok! now just adddoit.bat > test.txt
type test.txt |moreThe input will go to test.txt
The next line will display it.
Depending on the size you may not need the
pipe more command.hmmmm
Not much of a name, I know.I am just watching over the World Library machines and kids.Love playing with their connection as it goes anywhere. http,ftp,irc,icq,and has thousands of news groups.
Found the answer in the Library. Hope it is the right one for the problem.

That would work just fine.... except with a batch file.
Yes, at first that's what I thought the question was - how to get the screen output AND log to a .txt file.
Can't redirect a batch file in this manner - try it, and test.txt WILL be generated... but it's an empty (zero length) file.

I got the following to work by redirecting the output from within the dos batch file as previously suggested.
REM This is a batch file to make bkups of
REM directories c:\dir1 and c:\dir2.xcopy c:\dir1\* c:\bkup\dir1 /s > log.txt
xcopy c:\dir2\* c:\bkup\dir2 /s >> log.txtREM The first right arrow ">" places the.........
REM screen output from the first xcopy into...... REM log.txt. If log.txt does not exist it is..... REM created. If log.txt does exist it is......... REM replaced.....................................
REM The double arrow ">>" on the second..........
REM xcopy appends/adds the output to log.txt .... REM after the output already in log.txt from .... REM the first xcopy.

Sorry about the bad appearance above. Let me try this again....
I got the following to work by redirecting the output from within the dos batch file as previously suggested.
This is a batch file to make bkups of
directories c:\dir1 and c:\dir2.xcopy c:\dir1\* c:\bkup\dir1 /s > log.txt
xcopy c:\dir2\* c:\bkup\dir2 /s >> log.txtThe first right arrow ">" places the screen output from the first xcopy into log.txt.
If log.txt does not exist it is created.
If log.txt does exist it is replaced.
The double arrow ">>" on the second
xcopy appends/adds the output to log.txt.
Now log.txt contains screen output from
the first xcopy followed by screen output
from the second xcopy.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |