Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blinking cursor in BATCH file after echo command possible?

Tags:

batch-file

I would like to have my cursor blinking in a specific part of my running batch.

@echo off

REM some code goes here ... 

setlocal
for /f %%A in ('"prompt $H & echo on & for %%B in (1) do rem"') do set "BS=%%A"
set /p Menu=%BS%  Please inform your option {1,2,3} followed by ENTER:

Note that the with the SET /P command the cursor symbol "_" will be blinking in front of the word "ENTER" and right next to the colon symbol ":", awaiting the user decision as in ENTER: _

However, later on in my code I have the following :

REM some code goes also here ...
echo:
echo Please, press any key to return to main menu
pause>nul
Call Begin

In this case, the cursor waits the user command but it blinks somewhere else far, rather than next to the letter "U" of the word main menu

Question - How to make the cursor blink after the "U" next to the word menu ?

Thank you in advance !

like image 245
Luiz Vaughan Avatar asked Apr 24 '26 08:04

Luiz Vaughan


1 Answers

The ECHO command issues a new line at the end of your output, so the pause blinking cursor appears on the next line.

You can use SET /P to print your prompt without a new line to get your desired results.

<nul set/p"=Please, press any key to return to main menu"
pause>nul

BTW, You probably should not be using CALL to return to the main menu. There is a limit to the number of successive CALLs that can be issued without returning. I suspect your main menu is already CALLing a routine or batch file. Your main menu should probably be in a GOTO loop, and then have each option CALL a batch or routine. Then the CALLed routine can simply EXIT /B to return to the main menu.

like image 100
dbenham Avatar answered Apr 27 '26 04:04

dbenham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!