When adding a TextLog to Echo in Command Line, Input wont show up

前端 未结 1 1985
陌清茗
陌清茗 2020-12-20 08:48

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

相关标签:
1条回答
  • 2020-12-20 09:49

    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.

    0 讨论(0)
提交回复
热议问题