无法在 DOS 中输入变量



我正试图在vDOS(DOS模拟器(中运行一个批处理文件,我希望用户在其中输入两个变量。每次运行该文件时,它都不允许我输入变量。

SET /P in=Input:
SET /P out=Output:

我所期望的是,它会让我输入变量的输入。相反,它按原样执行这两个命令(不让我输入输入(。

Windows cmd和MS-DOS是非常不同的东西,其中一个区别是set命令。在MS-DOS中,集合的唯一形式是set variable=value。既没有set /Aset "variable=value"也没有set /P

set /P是Windows NT的cmd.exe的一个功能。在DOS中,您必须使用3rd方软件来获取用户输入并存储在变量中。以下是的一些解决方案

  • SENVAR.COM

    SENVAR INPUT Input string:
    
  • CCD_ 8和CCD_ 9

    editvar -p "Input string: " INPUT
    
  • FC.COM

    @echo off
    :: based on batch from PC Magazine June 27, 1995 page 248
    :: this version puts temps in C:DOS dir and shortens var names
    :: User input is returned in variable STR
    :input
    > C:DOSen#er.bat fc con nul /lb1 /n|date|find "    1:  "
    > C:DOSenter.bat echo set str=
    >>C:DOSenter.bat echo :loop
    >>C:DOSenter.bat echo if not '%%str%%==' set str=%%str%% %%5
    >>C:DOSenter.bat echo if '%%str%%==' set str=%%5
    >>C:DOSenter.bat echo shift
    >>C:DOSenter.bat echo if not '%%5==' goto loop
    call en#er.bat
    del C:DOSenter.bat
    del C:DOSen#er.bat
    
  • ANSI.SYS

    @ECHO OFF
    REM * Ask for USeR INPUT and store it in variable USRINPUT
    REM * Assumes ANSI.SYS is loaded
    REM * Written by Rob van der Woude
    SET USRINPUT=
    REM * Turn on ANSI key translation (translate Enter
    REM * key to F6+Enter sequence) and ask for input:
    ECHO ←[13;0;64;13pEnter one word only . . .
    REM * Copy entered text to temporary file:
    COPY CON %TEMP%.~USRINP.TMP
    REM * Turn off ANSI key translation and clear irrelevant screen output:
    ECHO ←[13;13p←[3A←[K←[1B←[K←[1B←[K←[2A
    REM * Add empty line to temporary file. The empty line
    REM * will be used to stop DATE asking for new date.
    ECHO.>> %TEMP%.~USRINP.TMP
    ECHO.>> %TEMP%.~USRINP.TMP
    
    REM * Create a temporary batch file that will store the
    REM * entered text into the environment variable USRINPUT:
    TYPE %TEMP%.~USRINP.TMP | DATE | FIND "):" > %TEMP%.~USRINP.BAT
    REM * Create more temporary batch files. Add
    REM * more command line parameters if necessary,
    REM * as in: ECHO SET USRINPUT=%%3 %%4 %%5 %%6 %%7 %%8 %%9>CURRENT.BAT
    ECHO SET USRINPUT=%%3>CURRENT.BAT
    REM * VOER.BAT and TYP.BAT are replacements for CURRENT.BAT for Dutch
    REM * DOS versions; add your own language versions if necessary:
    ECHO SET USRINPUT=%%6>VOER.BAT
    ECHO SET USRINPUT=%%4>TYP.BAT
    REM * This temporary batch file now sets the variable USRINPUT:
    CALL %TEMP%.~USRINP.BAT
    REM * Display the result:
    ECHO You typed: ←[1m%USRINPUT%←[0m
    ECHO.
    PAUSE
    REM * Finally, clean up the mess of temporary files:
    FOR %%A IN (%TEMP%.~USRINP.BAT %TEMP%.~USRINP.TMP VOER.BAT TYP.BAT CURRENT.BAT) DO DEL %%A
    

←是转义符(27h(

如果你只想得到简单的答案,比如Y/N,那么CHOICE.COM就是为这个目的而设计的

另请参见

  • MS-DOS 6.22批处理文件到环境变量的用户输入
  • DOS 7.1中的变量提示

/P直到Windows 2000或NT才被引入。传统的MS-DOS或等效系统不会有它。https://www.computerhope.com/sethlp.htm

相关内容

  • 没有找到相关文章

最新更新