Windows bat file press any key

MS-DOS Batch file pause with enter key

Is it possible in MS-DOS batch file to pause the script and wait for user to hit enter key?

I wish to do this inside a for loop. After each iteration, I want the script to pause and wait for user to hit ‘Enter’

5 Answers 5

There’s a pause command that does just that, though it’s not specifically the enter key.

If you really want to wait for only the enter key, you can use the set command to ask for user input with a dummy variable, something like:

set /p DUMMY=Hit ENTER to continue.

pause command is what you looking for. If you looking ONLY the case when enter is hit you can abuse the runas command:

the screen will be frozen until enter is hit.What I like more than set/p= is that if you press other buttons than enter they will be not displayed.

You can do it with the pause command, example:

Depending on which OS you’re using, if you are flexible, then CHOICE can be used to wait on almost any key EXCEPT enter

If you are really referring to what Microsoft insists on calling «Command Prompt» which is simply an MS-DOS emulator, then perhaps TIMEOUT may suit your purpose ( timeout /t -1 waits on any key, not just ENTER ) and of course CHOICE is available again in recent WIN editions.

And a warning on SET /P — whereas set /p DUMMY=Hit ENTER to continue. will work,

will detect whether just ENTER or something else, ending in ENTER was keyed in.

How do you make the Command Prompt window stay open after running a command?

Ok, I feel foolish asking this, because I knew the answer before. I’m learning how to program Visual C++. The book I have teaches how to write C++ and then goes into detail on writing the GUI part of Visual C++. The book I have walks me through compiling and making an exe file out of a cpp file, and then it says to go to the directory in Explorer and double-click on the exe file. I do this and the Command Prompt comes up for a quick second before closing down. The example in the book shows the output, and obviously the writer has his Command Prompt configured to pause after executing an exe.

Читайте также:  Cast from windows to samsung tv

I just want to configure my Command Prompt to do the same thing, so I can at least see the results. I know that the exe I wrote is working, but I’d like to see the output for less than one second.

I’m not sure how you are coding this. but if its like a normal batch or anything command line related.

Do the following to use a user defined switch at the end of the script.

To pause a DOS batch file in Windows XP from continuing to the next command, you can use the PAUSE command. Doing so prompts the user with the text:

Press any key to continue . . .

Then the batch file waits for the user to press a key. However, what if you want to pause a batch file and not display anything? Just pipe the results to nul like so:

pause > nul

Since this may not be very useful (how will the user know they need to press a key to continue the batch file?) you should display a different prompt. Issue an ECHO command with your desired prompt, then issue the above pause > nul command.

For example, to pause a Windows XP batch file with the prompt «Press ENTER to execute the command», use the following commands:

echo Press ENTER to execute the command
pause > nul
MCP. MCDST. LVL 80

C# — Batch file output not displaying “Press any key to continue…” until after I press a key

As the title says I have a batch file that uses a pause. This is an example batch file the I’ll use to explain the issue:

When running the batch file from the explorer it displays the following:

And then When the user presses a key the following is displayed:

The problem I’m having is that when running this .bat file from my windows forms application the output doesn’t display «Press any key to continue. » until after the user has pressed a key. This is a problem as the user needs to know that they need to press a key before they press it. Here is a Video displaying the issue.

Читайте также:  Пропали разрешения экрана windows 10 осталось только 640х480

When the batch file exectutes the circles on the left turn grey. The mouse then moves to the textbox and I press a key on the keyboard. Then the output textbox shows the text.

So Im experiementing and I add a line to the .bat file:

So here is the code:

What in the world do I need to do to get «Press any key to continue. » to display before the key is pressed?

This isn’t the only instance of this problem I’ve faced. If for example the batch file requires a value to be inputted as a response to a choice, the question doesn’t display until the answer has been inputted. e.g. «enter your name: » won’t display until after the user has inputted the name and pressed return at which point it will display «enter your name: Sample Name». Which is not helpful to the user because they need to know that they need to enter a name before they enter it.

I have many batch files which display alot of choices and the user is required to know what those choices are in order for my application to work. So this functionality is like the main bit. xD

EDIT So thanks to @MatthewMiller for providing me with a solution. And so here it is for everyone else:

Suppress the ‘press any key to continue’ in batch script

I am writing a batch script. After a stage in the command window it says ‘press any key to continue’ and halts, and after something is pressed the script continues. How can I prevent this in the script?

3 Answers 3

That’s the output of the PAUSE command:

The problem with PAUSE is that it’s often necessary when you run a batch file from Windows explorer (or you cannot read the output) but it’s annoying in the command prompt. I asked about it here and I was suggested a nifty trick:

Pause>nul Will make it not echo ‘press any key to continue . . .’

you can call other script like this from source, @echo | call otherScript.bat please find the detailed answer here Another thread with example

Not the answer you’re looking for? Browse other questions tagged batch-file or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Читайте также:  Hp universal printing pcl 6 windows 2003

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Флешка сисадмина часть 7. Как убрать Press any key to boot from CD or DVD

Если Вы уже записали образ на флешку и опробовали его в действии, то наверняка заметили при загрузке надоедливую надпись Press any key to boot from CD or DVD. Вдаваться в подробности, что она означает в рамках данного поста я не буду. Расскажу лишь как убрать из образа с Windows 7 эту раздражающую деталь. Те кого данная особенность сборки Windows не напрягает, могут пропустить чтение этой статьи. Но я всё же рекомендую с ней ознакомиться, хотя бы из любопытства. Никогда нельзя угадать какие знания пригодятся нам завтра.

Вот так выглядит наша проблема на экране монитора.

1 шаг. Распаковываем наш образ с Windows 7 в отдельную папку. Я создал папку W764 и распаковал туда.

2 шаг. Находим в папке BOOT файл bootfix.bin и удаляем его.

3 шаг. Отлично. Теперь нужно запаковать образ обратно. Для этого скачиваем и устанавливаем программу ImgBurn 2.5.8.0 (скачать).

4 шаг. Запускаем программу и выбираем «Создать образ из файлов/папок”.

5 шаг. Указываем программе путь к папке с нашим дистрибутивом Windows 7.

6 шаг. После указания папки перейдём на вкладку “Дополнительно” и в открывшейся дополнительной панели на вкладку “Загрузочный диск”. После установки флажка “Сделать образ загрузочным” укажем программе местонахождение файла etfsboot.com (папка BOOT нашего дистрибутива).

7 шаг. Осталось сделать несколько завершающих действий:

    • В поле ID разработчика введите Microsoft Corporation;
    • В поле Загруз. сегмент – 07 C0;
    • В поле Загруж. секторов – 8. (Примечание: это значение рассчитывается в зависимости от величины файла etfsboot.com. Если оно равно 2кБ, то устанавливается значение 4 (2048 / 512), если 4кБ — 8 (4096 / 512). Поэтому для Windows 7 устанавливается значение 8);
    • В поле Назначение введите местоположение и название будущего файла образа;
    • Нажмите знак начала работы программы.

8 шаг. Согласитесь с исправлением, которое предлагает сделать программа.

9 шаг. Заполните поля Метки тома, подтвердите итоговую информацию, дождитесь окончания процесса создания образа.

Это последний урок по созданию сборки Windows 7. Теперь вы знаете как убрать Press any key to boot from CD or DVD. В следующих статьях подробно будет расписан мой метод настройки персональных компьютеров уже после установки операционной системы!

Пишите свои вопросы и пожелания в комментариях под данной статьёй, ставьте лайки, подписывайтесь на мой блог в форме справа.

Оцените статью