Output text without linefeed, even with leading space or =

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
dbenham
Expert
Posts: 2451
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Output text without linefeed, even with leading space or =

#16 Post by dbenham » 11 Jul 2021 09:24

:shock: SWEET :!: :D

atfon
Posts: 131
Joined: 06 Oct 2017 07:33

Re: Output text without linefeed, even with leading space or =

#17 Post by atfon » 18 Nov 2021 10:16

I love the "%comspec%" /d /k <nul solution here. However, I have a situation using this technique that I haven't been able to solve. Let's say I have a very simple menu like this:

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f %%g in ('%__APPDIR__%forfiles.exe /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "bel=%%g"
for /F "delims=#" %%e in ('"prompt #$E# & for %%e in (1) do rem"') do set "ESC=%%e"
:top
cls
echo(
echo    Main Menu
echo(
echo    1...............................................Refresh
echo    2...............................................Quit
echo(
set "prompt=   SELECT FROM THE MENU ABOVE AND PRESS [Enter]:"
"%comspec%" /d /k <nul
set /p "INPUT="
IF '%INPUT%'=='1' GOTO refresh
IF '%INPUT%'=='2' GOTO quit
:refresh
goto top
:quit
exit /b
Now, suppose I want to use a terminal escape sequence to display a title rather than using just the title command (so that it appears the same when run as Administrator or not):

Code: Select all

echo %ESC%]0;Main Menu%BEL%
Where can I use this terminal escape sequence in this scenario?

Edit:
To clarify somewhat further, if I put the terminal escape sequence for the title and run as Administrator, the title will appear as "Main Menu" until it hits the %comspec% line, when it changes to "Administrator: Main Menu." I'm trying to avoid that change.

Edit 2: I can sort of get it to work if I use this:

Code: Select all

"%comspec%" /d /k <nul & echo %ESC%]0;Main Menu%BEL%
However, that introduces the issue of a carriage return to the next line. Any suggestions?

jeb
Expert
Posts: 993
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Output text without linefeed, even with leading space or =

#18 Post by jeb » 19 Nov 2021 02:07

Hi atfon,
escape sequences can be outputted with the `set /p` technique.

Code: Select all

"%comspec%" /d /k <nul & <nul set /p ".=%ESC%]0;Main Menu%BEL%"

atfon
Posts: 131
Joined: 06 Oct 2017 07:33

Re: Output text without linefeed, even with leading space or =

#19 Post by atfon » 19 Nov 2021 06:56

jeb wrote:
19 Nov 2021 02:07
Hi atfon,
escape sequences can be outputted with the `set /p` technique.

Code: Select all

"%comspec%" /d /k <nul & <nul set /p ".=%ESC%]0;Main Menu%BEL%"
Thanks Jeb! I tried a bit with set /p, but didn't think to use the ".= for this. Worked like a charm. :)

Post Reply