I feel bad for asking so many questions, This is my second today. But i need help with batch.
I code in C++ when i want to create programs but i am trying to learn batch just in case it is of any use to me in the future.
My problem is when my batch file runs it runs very quickly and i was wondering if there was a way of fixing it equivalent to something like system("pause"); or cin.get();
[code]
@echo off
echo hello
echo world
[/code]
[code]
@echo off
echo hello
echo world
pause
[/code]
system("*") in C++ is equivalent to * in batch (under windows)
Ah i see, Thank you much.
If you don't want the "Press any key to continue..." to show up, use:
[code] PAUSE >nul [/code]
or you [code]set /p somthing=[/code]
[QUOTE=Nisd;18727602]or you [code]set /p somthing=[/code][/QUOTE]
no, that's to ask the user to input a value as variable %something%
[code]
echo some text here...
pause >NUL
echo ...and the rest here
[/code]
will appear as:
[code]
some text here... _ [I]you press any key[/I]
...and the rest here
[/code]
[QUOTE=robmaister12;18749231]no, that's to ask the user to input a value as variable %something%
[/QUOTE]
That's what i was going to say. You use "set /p" to input a variable.
[QUOTE=Deadollie;18751334]That's what i was going to say. You use "set /p" to input a variable.[/QUOTE]
for some reason I didn't read cin.get()... for inputting a variable yes, but don't substitute it for a pause
[editline]12:58PM[/editline]
if you want to choose what each input for a set /p line does, follow it up like this:
[code]
set /p myvar=""
if %myvar%=hello goto world
if %myvar%=backup xcopy "file" "destination"
:world
echo hello world
[/code]
you can put anything inside the quotes on the SET line, for example:
[code]
echo. Continue?
set /p cont="[y/n] "
if %cont% = y goto yes
if %cont% = n goto no
:no
echo.
echo no
:yes
echo.
echo yes
[/code]
will appear as
[code]
Continue?
[y/n] [B]y[/B] [I]<enter>[/I]
yes
[/code]
[code]
Continue?
[y/n] [b]n[/b] <enter>
no
yes
[/code]
Just sayin'
[QUOTE=turby;18778901][code]
Continue?
[y/n] [b]n[/b] <enter>
no
yes
[/code]
Just sayin'[/QUOTE]
Also:
[code]
Continue?
[y/n] <enter>
no
yes
[/code]
[QUOTE=arienh4;18779123]Also:
[code]
Continue?
[y/n] <enter>
no
yes
[/code][/QUOTE]
true
[code]echo. Continue?
set /p cont="[y/n] "
if %cont% = y goto yes
if %cont% = n goto no
goto cont
:no
echo.
echo no
goto cont
:yes
echo.
echo yes
goto cont
:cont
[/code]
?
[editline]10:15AM[/editline]
Maybe something different than cont, as used as var
[QUOTE=I am a noob;18780344][code]echo. Continue?
set /p cont="[y/n] "
if %cont% = y goto yes
if %cont% = n goto no
goto cont
:no
echo.
echo no
goto cont
:yes
echo.
echo yes
goto cont
:cont
[/code]
?
[editline]10:15AM[/editline]
Maybe something different than cont, as used as var[/QUOTE]
Try not to have GOTO after each if. I normally use:
[code]
if %cont%== Y (
ECHO I use brackets because i'm cool
ECHO dawg.
PAUSE >nul
GOTO Whutever
)
if %cont%== N (
ECHO I eat sand because i'm cool
ECHO dawg.
PAUSE >nul
GOTO Whutever
)
[/code]
Sorry, you need to Log In to post a reply to this thread.