How do I make a log of all ECHO commands in a BATCH file?

后端 未结 4 1810
猫巷女王i
猫巷女王i 2020-12-03 11:39

I am trying to use a BATCH file as a choose your own adventure story in which the user can create a character and be called by name and such by the characters in the story.

4条回答
  •  既然无缘
    2020-12-03 12:15

    You cannot do that in batch script literally, but if you define functions, you can output data within the function block that also writes to a log file before the function returns, like so:

    @ECHO off
    SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
    echo. 2>outfile.log
    
    CALL :functionPerson "Jon Doe" jump
    GOTO :END
    :functionPerson fullname action
      ECHO fullname is ^"%~1^"
      ECHO action is %2
      ECHO %1 performs action %2>> outfile.log
    EXIT /B 0
    :END
    pause
    

提交回复
热议问题