./ startup.sh> output.txt的
但在Windows中,我们可以使用.bat脚本执行类似的操作。
我怎么能写这个蝙蝠脚本???
(我知道正确的方法应该要求应用程序执行日志,但是应用程序不是由我编写的,他们使用system.out.print打印日志,所有日志都在控制台中,但我想要存档日志,以防万一发生,我可以回溯跟踪)
答案 0 :(得分:4)
在Windows中完全相同。
即
ping google.com > logfile.txt
或在powershell中,您可以执行以下操作以显示日志到控制台
ping google.com | tee-object -filepath C:\mylog.txt
答案 1 :(得分:1)
来自Linux世界,你会发现这些unxutils对于windows非常有用。有了它你甚至可以说:
whatever | tee.exe text.txt
...查看输出并同时将其保存到text.txt。
答案 2 :(得分:0)
您可以编写一个条形脚本来执行您想要的所有操作,然后将整个输出发送到文件,或者您可以通过在.bat文件中指定重定向来指定输出的某些部分。
案例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:\>
案例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:\>