Reputation: 13863
in linux, let say i want to start tomcat, and want to direct all the console log into a text file, i can do write a bash script:
./startup.sh > output.txt
but in windows, can we do the similar stuff using .bat script.
how can i write this bat script???
(i know the proper way should ask the application to do the log, but the application is not written by me, they print the log using system.out.print, all the logs are in the console, but i want to archive the log, in case something happen i can back trace)
Upvotes: 1
Views: 15862
Reputation: 5453
You can write a bar script to do all that you want and then send the entire output to a file or you can specify some portion of the output to file by specifying the redirection in side the .bat file.
Case 1:
C:\>copy con 1.bat dir pause dir /b^Z 1 file(s) copied. C:\>1 C:\>dir Volume in drive C is Windows Volume Serial Number is A4FA-F45F Directory of C:\ 10/25/2009 06:05 PM 18 1.bat 12/19/2007 10:13 AM <DIR> Documents and Settings 09/04/2009 05:30 AM <DIR> Program Files 10/20/2009 11:48 PM <DIR> WINDOWS 1 File(s) 86,525 bytes 3 Dir(s) 946,864,128 bytes free C:\>pause Press any key to continue . . . C:\>dir /b 1.bat Documents and Settings Program Files WINDOWS C:\>1 > test1.txt C:\>type test1.txt C:\>dir Volume in drive C is Windows Volume Serial Number is A4FA-F45F Directory of C:\ 10/25/2009 06:05 PM 18 1.bat 12/19/2007 10:13 AM <DIR> Documents and Settings 09/04/2009 05:30 AM <DIR> Program Files 10/25/2009 06:06 PM 0 test1.txt 10/20/2009 11:48 PM <DIR> WINDOWS 2 File(s) 86,525 bytes 3 Dir(s) 946,860,032 bytes free C:\>pause Press any key to continue . . . C:\>dir /b 1.bat Documents and Settings Program Files test1.txt WINDOWS C:\>
Case 2:
C:\>copy con 2.bat
dir
pause
dir /b > test2.txt^Z
1 file(s) copied.
C:\>2
C:\>dir
Volume in drive C is Windows
Volume Serial Number is A4FA-F45F
Directory of C:\
10/25/2009 06:05 PM 18 1.bat
10/25/2009 06:14 PM 30 2.bat
12/19/2007 10:13 AM <DIR> Documents and Settings
09/04/2009 05:30 AM <DIR> Program Files
10/25/2009 06:06 PM 1,112 test1.txt
10/20/2009 11:48 PM <DIR> WINDOWS
3 File(s) 87,667 bytes
3 Dir(s) 946,601,984 bytes free
C:\>pause
Press any key to continue . . .
C:\>dir /b 1>test2.txt
C:\>type test2.txt
1.bat
2.bat
Documents and Settings
Program Files
test1.txt
test2.txt
WINDOWS
C:\>
Upvotes: 0
Reputation: 1552
It's exactly the same in Windows.
i.e
ping google.com > logfile.txt
or in powershell you could do the following to display the log to console as well
ping google.com | tee-object -filepath C:\mylog.txt
Upvotes: 5