当添加TextLog在命令行回声,输入不会显示出来 [英] When adding a TextLog to Echo in Command Line, Input wont show up
问题描述
我知道,当我们添加了>>
在回声
输出的作品,但在命令行本身这是隐藏的。我想知道,如果有一种方法,而无需复制我的code我都可以做。所以,它应该显示在命令行和输出文件。
回声###备份驱动器和GT;> %驱动器%:\\备份\\备份 - Log.txt文件
平127.0.0.1> NUL
XCOPY%HOMEDRIVE%\\ DRIVERS/ C / D / H / E / I / Y%驱动器%:\\备份\\ DRIVERS>> %驱动器%:\\备份\\备份 - Log.txt文件呼应###备份注册表...>> %驱动器%:\\备份\\备份 - Log.txt文件
如果不存在%驱动器%\\注册表的mkdir%驱动器%:\\备份\\注册表
如果存在%驱动器%\\注册\\ regbackup.reg回声更换%驱动器%:\\备份\\注册\\ regbackup.reg>> %驱动器%:\\备份\\备份 - Log.txt文件
如果存在%驱动器%\\注册\\ regbackup.reg删除%驱动器%:\\备份\\注册\\ regbackup.reg>> %驱动器%:\\备份\\备份 - Log.txt文件
注册表编辑器/ C / D / H / E / I / Y%驱动器%:\\备份\\注册\\ regbackup.reg>> %驱动器%:\\备份\\备份 - Log.txt文件
下面是我的一个老的答案
解释为此我使用了以下内容:
设置日志文件= somepath \\ LOGFILE.TXT
集LOGG = ^> _ ^&放大器; ^&安培;键入_ ^&放大器; ^&放大器;类型_ ^> ^>%日志文件%
这呼应进入屏幕和文件! %LOGG%
这是一个有点棘手。因此,让我们拆开该行四部分:
集LOGG = ^> _ ^&放大器; ^&安培;键入_ ^&放大器; ^&放大器;类型_ ^> ^>%日志文件%
我们的想法是打印行到一个临时文件(名为_)(第二部分),然后键入文件的内容屏幕(第三部分),然后将其输入到日志文件(第四部分)。
把所有的一个变量(第一部分),所以你不必键入monsterstring到每一行。 (这就是为什么>和&放大器;的原因被转义为^)
所以,每次使用时间
回声无论%LOGG%
它就会出现在屏幕上,并写入日志文件%%
您可以在这里找到完整的答案:<一href=\"http://stackoverflow.com/questions/15551379/how-do-i-make-a-log-of-all-echo-commands-in-a-batch-file/15553922#15553922\">How做我做一个批处理文件记录所有ECHO的命令?
注:
有一个&安培;
就足够了,所以不是 ^&放大器; ^&安培;
只写 ^&安培;
缺点是:它产生磁盘IO每一次,你用它
I know when we add the >>
after echo
the output works but in the command line itself it's hidden. I'd like to know if there is a way I can do both without duplicating my code. So it should show in the command line and the output file.
Echo ### Backing up Drivers >> %Drive%:\Backup\Backup-Log.txt
Ping 127.0.0.1 >nul
xcopy "%HOMEDRIVE%\drivers" /c /d /h /e /i /y "%Drive%:\Backup\Drivers" >> %Drive%:\Backup\Backup-Log.txt
echo ### Backing up the Registry... >> %Drive%:\Backup\Backup-Log.txt
if not exist "%Drive%\Registry" mkdir "%Drive%:\Backup\Registry"
if exist "%Drive%\Registry\regbackup.reg" Echo "Replacing %Drive%:\Backup\Registry\regbackup.reg" >> %Drive%:\Backup\Backup-Log.txt
if exist "%Drive%\Registry\regbackup.reg" del "%Drive%:\Backup\Registry\regbackup.reg" >> %Drive%:\Backup\Backup-Log.txt
regedit /c /d /h /e /i /y "%Drive%:\Backup\Registry\regbackup.reg" >> %Drive%:\Backup\Backup-Log.txt
Here is an explanation from an old answer of mine
for this purpose I use the following:
set LogFile=somepath\logfile.txt
set logg=^> _^&^& type _^&^&type _^>^>%LogFile%
echo this goes to screen AND file! %logg%
This is a bit tricky. So let's disassemble that line to four parts:
set logg= ^> _ ^&^& type _ ^&^&type _^>^>%LogFile%
The Idea is to print the line to a temporary file (named "_") (second part) then type the contents of that file to screen (third part) then type it to the logfile (fourth part).
Put that all to a variable (first part), so you don't have to type that monsterstring to every line. (this is the reason why the ">" and "&" are escaped with "^")
So every time you use
echo whatever %logg%
it will appear on the screen AND write to %logfile%
You can find the complete answer here: How do I make a log of all ECHO commands in a BATCH file?
NOTES:
one &
is enough, so instead of ^&^&
write only ^&
The disadvantage is: it generates Disk-IO every time, you use it.
这篇关于当添加TextLog在命令行回声,输入不会显示出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!