How to save my variable input to the original batch file after I have typed it into the command prompt?

前端 未结 1 2037
夕颜
夕颜 2020-12-21 17:36

I would like to save my input for %x% to the Batch file once I type it in the command prompt. Please see below.

@ECHO OFF
TITLE Access to OST Documents for t         


        
相关标签:
1条回答
  • 2020-12-21 17:56
    @echo off
    call :getvar
    if not "%x%" == "" goto :continue
    REM var not set; ask user:
    REM insert your input code and verification here
    REM write it to the end of this batch:
    echo set "x=%x%">>"~f0"
    :continue
    REM rest of your code
    REM the following line should be the very last line in this batch (but WITH a CRLF):
    :getvar
    

    The call :getvar tries to set the variable (comes back empty for the first run)
    The if line checks, if empty (then the user gets asked)
    echo set "x=%x%">>"~f0" is the key here. It adds the set command to the batch file (%~f0 is the batch file's full name), so
    call :getvar comes back with the previously set variable %x%

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