Computer Hope
Microsoft => Microsoft DOS => Topic started by: Two-eyes on September 05, 2009, 04:13:22 AM
-
hi there,
i wrote a simple batch file that pings the localhost for an amount of time specified by the user (called wait.bat), and it works fine.
Then i wrote another batch file that calls wait.bat, but the commands after the call do not work.
Can anyone tell me why this is happening?
Two-eyes
CODE:
wait.bat:
@echo off
ping localhost -n %1 -w 1000 > nul
testwait.bat
@ echo off
echo %time%
wait.bat 3
start cmd.exe
echo %time%
I also tried this:
@ echo off
echo %time%
REM HERE \/
ping localhost -n 3 -w 1000 > nul
start cmd.exe
echo %time%
and it worked, so it must be the batch file.
Thanks
-
Try adding EXIT ath tye end of your code. Like this:
@echo off
Commands here
EXIT
That will make sure when you call it, it will exit and return to the calling batch file.
-
if you meant in the wait.bat, it didn't work. It closed the cmd.
Thanks, though :)
-
Try exit /b then. Try adding PAUSE after each line to see where it's not working (in both batch files).
-
dang it. I put pause after the commands but here's the output (also check the code i supplied):
The output:
...the time
press any key... <-- after echo time
press any key... <-- inside wait.bat
and here it stopped.
CODE:
testwait.bat:
@ echo off
echo %time%
pause
wait.bat 3
pause
start cmd.exe
pause
echo %time%
wait.bat:
@echo off
ping locahost -n %1 -w 1000 > nul
pause
exit /b
Thanks dude for your patience :)
-
Newbie batch lesson #1, seemingly needed:
if, in a batch file, you just place the name of another batch file as a command, then control will transfer to the second batch file and never come back.
You all talk about "calling" the other batch file; yet nobody remembered the call command, which hands back control after the called batch file terminates. (If it does!)
wrong: (If you want to execute the lines after batch2.bat)
@echo off
batch2.bat
REM this line never executes
right:
@echo off
call batch2.bat
REM this line will execute when batch2.bat is finished
-
wooops...that was it...probably skipped lesson 1 ;P
Thanks all
Two-eyes
-
probably skipped lesson 1
It wasn't you I meant ;)
-
please do not implicate me in your rivalry.
::)
-
please do not implicate me in your rivalry.
::)
I already explicitly excluded you (did you not see my winking emoticon, which means "This is a joke between friends"?)
-
C:\>type main.bat
@echo off
call wait.bat
echo this line will execute when wait.bat is finished
C:\>type wait.bat
echo will sleep 3
C:\batextra\sleep 3
exit /b
Output:
C:\> main.bat
will sleep 3
this line will execute when wait.bat is finished
C:\>
( will need to download sleep from the internet )
-
The OP was making a sleep command with PING.
-
The OP was making a sleep command with PING.
The sleep.exe command is better than ping
-
@ST: it's the emails i'll recieve that i'm talking about.
@bill: didn't look for sleep...hmmm
@helpmeh: was that an insult?...no wait...don't wanna know...
Is there a way to close a thread, pls?
Two-eyes
-
@ST: it's the emails i'll recieve that i'm talking about.
What emails? What are you talking about?
-
@helpmeh: was that an insult?...no wait...don't wanna know...
Is there a way to close a thread, pls?
Two-eyes
No that wasn't an insult at all. Mods can close threads, but there is no need here.
-
the 6 e-mails saying: a reply has been posted on the topic. but now i see a little checkbox down help...let's uncheck it and hope :)
Two-eyes
Just forget bout it
-
Just forget bout it
Gladly
::)