how to do "press enter to exit" in batch

Batch FileRake

Batch File Problem Overview


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 window pops up and shows all the progress but closes itself when the task is finished. Is there way to do a Console.ReadLine so that user can get a chance to see the log?

Thanks.

Updated:

I've tried below but didn't work. not sure why.

@echo off
cls
rake
pause

Batch File Solutions


Solution 1 - Batch File

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.

Solution 2 - Batch File

pause

will display:

> Press any key to continue . . .

Solution 3 - Batch File

@echo off
echo something
echo Press enter to exit
set /p input=

Solution 4 - Batch File

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

Solution 5 - Batch File

@echo off
echo Press any key to exit . . .
pause>nul

Solution 6 - Batch File

Oops... Misunderstood the question...

Pause is the way to go

Old answer:

you can pipe commands into your patch file...

try

build.bat < responsefile.txt

Solution 7 - Batch File

Use this snippet:

@echo off
echo something
echo.
echo press enter to exit
pause >nul
exit

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJeffView Question on Stackoverflow
Solution 1 - Batch FileBasilevsView Answer on Stackoverflow
Solution 2 - Batch FileSteven RobbinsView Answer on Stackoverflow
Solution 3 - Batch FileRatajSView Answer on Stackoverflow
Solution 4 - Batch FileAaron DigullaView Answer on Stackoverflow
Solution 5 - Batch FilebluevariantView Answer on Stackoverflow
Solution 6 - Batch FileHeiko HatzfeldView Answer on Stackoverflow
Solution 7 - Batch FileBarthView Answer on Stackoverflow