views:

1668

answers:

3

I have a batch script that executes a task and sends the output to a text file. Is there a way to have the output show on the console window as well?

For Example:

c:\Windows>dir > windows-dir.txt

Is there a way to have the output of dir display in the console window as well as put it into the text file?

Thanks

+3  A: 
command > file >&1
Otávio Décio
Doesn't work under Windows or DOS.
andynormancx
+1 Thats how you do it. example DIR > DIR.txt
Ioxp
andynormancx
Its faster when you do not write the data out to the screen as your not filling the buffer up with crap but rather letting you batch job run. if you are debugging i would not use the > file syntax.
Ioxp
@andynormancx yup forgot to type that instead of cut and paste from the CMD.
Ioxp
I could not get the syntax to work under a windows command prompt and have went with the type command instead.
JamesEggers
JamesEggers
What exact command line are you using ?
andynormancx
I'm just using the typical Start > Run > cmd
JamesEggers
I meant what exactly is in the line of .bat command that isn't doing what you want.
andynormancx
JamesEggers
+1  A: 

If you don't need the output in real time (i.e. as the program is writing it) you could add

type windows-dir.txt

after that line.

Mark Pim
A: 

The solution that worked for me was: dir > a.txt | type a.txt.

tori3852