how to do “press enter to exit” in batch

后端 未结 7 1198
眼角桃花
眼角桃花 2021-02-06 19:59

I am using rake to build my project and I have a build.bat file similar to this:

@echo off
cls
rake

When I double click on build.bat the dos wi

相关标签:
7条回答
  • 2021-02-06 20:30

    Use this snippet:

    @echo off
    echo something
    echo.
    echo press enter to exit
    pause >nul
    exit
    
    0 讨论(0)
  • 2021-02-06 20:36
    @echo off
    echo somethink
    echo Press enter to exit
    set /p input=
    
    0 讨论(0)
  • 2021-02-06 20:43
    pause
    

    will display:

    Press any key to continue . . .

    0 讨论(0)
  • 2021-02-06 20:48

    Default interpreters from Microsoft are done in a way, that causes them exit when they reach EOF. If rake is another batch file, command interpreter switches to it and exits when rake interpretation is finished. To prevent this write:

    @echo off
    cls
    call rake
    pause
    

    IMHO, call operator will lauch another instance of intepretator thereby preventing the current one interpreter from switching to another input file.

    0 讨论(0)
  • 2021-02-06 20:52

    My guess is that rake is a batch program. When you invoke it without call, then control doesn't return to your build.bat. Try:

    @echo off
    cls
    CALL rake
    pause
    
    0 讨论(0)
  • 2021-02-06 20:56
    @echo off
    echo Press any key to exit . . .
    pause>nul
    
    0 讨论(0)
提交回复
热议问题