I want to have multiple echo and echo. below a pause and below a set /p variable= befor pressing any key in a batch file - batch-file

I want the line of code below to work or something that will do the same and i want the echo and echo. to show befor i press any key
set /p variable=
echo.
echo test
echo.
echo test
::ect
and I want the line of code below to work or something that will do the same and i want the echo and echo. to show befor i press any key
pause
echo.
echo test
echo.
echo test
::ect
I tried this (I have not tried it with pause)
#echo off
for /f %%A in ('echo prompt $E^| cmd') do set "esc=%%A"
cls
echo *other text*%ESC%[2A
set /p variable=
echo %ESC%[1B
I was only able to have one echo or one echo. after set /p variable=, but I expected to be able to have multiple echo below set /p variable= and multiple echo. below set /p variable=
If i try to have more then one line of text then it takes the line of text above set /p variable= and moves it down below set /p variable= and combines it with the text i want below set /p variable=
So i want the set /p variable= and pause to pause after all the echo and echo.
I want it to look like for example this when i open the .bat file
Type the number of your choosing:
*other text*
Or this
Press any key to continue . . .
*other text*
sorry for posting the same thing so many times i promis that this is the last time

You are using ANSI escape codes. Just use them at the right place and with the proper parameters (numbers):
#echo off
for /f %%A in ('echo prompt $E^| cmd') do set "esc=%%A"
cls
echo/
echo/
echo *other text*
echo *additional text*
echo *some more text*
echo %ESC%[5A
set /p "variable=Enter var: "
echo %ESC%[2B
echo Thank you for your input.
Output on screen (where Hello is the manual input:
Enter var: Hello
*other text*
*additional text*
*some more text*
Thank you for your input.
You need enough space "above" set /p. It doesn't work at the very first line (after CLS) because you can't move the cursor to "line zero", so you need (at least) two (empty) lines (echo/).

Related

How to display text beneath "set /p variable="

In this senario,
echo Write your name below.
echo.
set /p name="Enter here: "
echo.
echo *other text*
is there a way where the set /p name="Enter name: " doesn't pause the screen and also displays the text below.
I figured that since its a top down language it probably cannot, but there are many people on here with more experience who might no otherwise.
If you're using Windows 10, you can use VT100 escape sequences to move the cursor up and down, printing everything first and then getting user input afterwards.
#echo off
:: Generate an escape character. Normally I'd just use ALT+027,
:: but SO doesn't display those properly.
for /f %%A in ('echo prompt $E^| cmd') do set "esc=%%A"
:: The trick here is to write out everything and then move the cursor
:: back to where it needs to be
echo Write your name below.
echo(
echo(
echo(
echo *other text*%ESC%[2A
set /p "name=Enter here: "
:: When we're done, move the cursor to where it would have been if
:: we had written everything top-down
echo %ESC%[1B
You can store new line character in a variable and print it out
#echo off
setlocal EnableDelayedExpansion
(set LF=^
%=empty=%
)
echo Write your name below.
echo.
set /p name="Enter here:!LF!*other text*!LF!"

How to use call echo in a string

I am using a menu and want to write to a file with selected name in dropdown. It's working fine except the file name is incorrect.
It's naming it " ws-%Name[2]% " and not putting the correct value in.
How can I fix this this? thanks for any help
ECHO OFF
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO Select Postroom staff:-
ECHO ...............................................
ECHO.
set "Name[1]=Diana Mckinley"
set "Name[2]=Lenka Smolkova"
set "Name[3]=Louise Smith"
set "Name[4]=Sally Baldwin"
set "Name[5]=Sally Faulkner"
set "Name[6]=Sarah Kendle"
set "Name[7]=Sophie Jennings"
set "Name[8]=Steven Caylor"
:MenuLoop
set /a "x+=1"
if defined Name[%x%] (
call echo %x%. %%Name[%x%]%%
goto MenuLoop
)
ECHO.
SET /P index=Type KEY then press ENTER to register:
call echo %%Name[%index%]%% is now registered
call echo %%Name[%index%]%% > "C:\Users\karim ali\Documents\Test\ws-%%Name[%index%]%%.txt"
GOTO MenuLoop
All you'll need to do is to set that name and index as a variable and use that.
Here is an example with a few changes for demonstation purposes:
#ECHO OFF
SET "Name[1]=Diana Mckinley"
SET "Name[2]=Lenka Smolkova"
SET "Name[3]=Louise Smith"
SET "Name[4]=Sally Baldwin"
SET "Name[5]=Sally Faulkner"
SET "Name[6]=Sarah Kendle"
SET "Name[7]=Sophie Jennings"
SET "Name[8]=Steven Caylor"
:MENU
CLS
ECHO.
ECHO ...............................................
ECHO Select Postroom staff:-
ECHO ...............................................
ECHO.
:MenuLoop
FOR /F "TOKENS=2-3 DELIMS==[]" %%A IN ('SET Name[') DO (
CALL ECHO %%A. %%Name[%%A]%%)
ECHO.
SET /P index=Type KEY then press ENTER to register:
CALL SET "PRSName=%%Name[%index%]%%"
ECHO.
ECHO %PRSName% is now registered
TIMEOUT 2 /NOBREAK 1>NUL
ECHO %PRSName%>"C:\Users\karim ali\Documents\Test\ws-%PRSName%.txt"
SET "Name[%index%]="
SET Name[>NUL 2>&1&&(GOTO :MENU)
expansion of nested variables can be confusing...
instead of ws-%%Name[%index%]%%.txt, write ws-%Name[%%index%%]%.txt

Test for and remove substring in user input

I want to create a batch file that echoes text that it receives as part of a user-inputted command.
#echo off
Echo execute a command
Set /p command=
if "%command%"=="echo 'some text'" goto echo
::my aim is to make "echo" ignored by System and Only read "'some text'"
:: like "set text_to_echo='some text'
:echo
echo %text_to_echo%
Asking the user for the command first and then asking the user what to echo, like below, is not an option
#echo /p
set /p text=
if "%text%=="echo"
:echo
set /p tex1="Enter text to echo"
echo "%tex1%"
You could use this:
#echo off
Echo execute a command
Set /p "command="
if NOT "%command%"=="%command:echo =%" goto echo
pause
:echo
SET "text_to_echo=%command:~5%"
echo.%text_to_echo%
pause
Note that I also fixed your if, and put a pause after your if so you know whether it goes to :echo or not.
You want to split your Input into a first word (token) and the rest. You can do this with a for:
#echo off
Echo execute a command
Set /p "commandstring=# "
for /f "tokens=1,* delims= " %%a in ("%commandstring%") do (
set "command=%%a"
set "params=%%b"
)
if /i "%command%"=="echo" goto :_echo
...
:_echo
echo %params%
REM also possible (at least for "echo", but I guess, that's just an example):
%command% %params%

ask set /p variable on a different line

I've seen in batch code that you can ask for user input on a separate line or continue while asking or something. For example it would look something like this;
enter your name
name:_(input would be here)
enter name above
And the code might look like;
echo Enter your name
set /p /(continue) name=name:_
echo enter name above
Or maybe:
echo enter your name
(line 2)
echo enter your name above
set /p /line:2 name=name:_
#echo off
setlocal
cls
echo enter your name
echo name:
echo enter name above
rem Move cursor to one line below screen size,
rem you must adjust this value to fit your screen.
for /L %%i in (1,1,34) do echo/
rem Move cursor to screen home and hide timeout "Waiting..." message
for /F %%a in ('timeout /T 1 ^> CON') do rem
set /P "name=name: "
echo/
echo/
echo/
echo Name read: "%name%"
Further details at this post

How to use the echo command after a set /p command

I wanted to make this script work somehow, but i find that after you use
set /p variable= whater you want here
If you use the echo command after it, its hidden or something because it wont come up...
#echo off
cls
color A
:MAIN
cls
echo.
echo.
echo =================================
echo. set /p var= what is your name?
:: DOES NOT SHOW UP (STARTING HERE)
echo.
echo =================================
:: DOES NOT SHOW UP (ENDING HERE)
set /p answer= so your name is %var%?
IF %answer%== yes echo thats an amazing name!
IF %answer%== no goto MAIN
The part thats surrounded by the remarks doesnt want to show up for some reason... any ideas?
If I'm understanding what you are trying to do, this is the code you need:
#echo off
cls
color A
:MAIN
cls
echo =================================
echo what is your name?
echo =================================
set /p var=
set /p answer= so your name is %var%?
IF [%answer%] == [yes] echo thats an amazing name!
IF [%answer%] == [no] goto MAIN
pause
Because the processor will wait for the user input after printing what is your name? (due to the /p), you will not get the next line of ========etc. until enter is pressed.
It shows up for me, I get
=================================
set /p var= what is your name?
=================================
so your name is ? Andy
Which is what I would expect, what are you expecting?

Resources