Computer Hope

Microsoft => Microsoft DOS => Topic started by: Two-eyes on September 05, 2009, 04:13:22 AM

Title: commands after batch file that pings not working
Post 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:
Code: [Select]
@echo off
ping localhost -n %1 -w 1000 > nul

testwait.bat
Code: [Select]
@ echo off
echo %time%
wait.bat 3
start cmd.exe
echo %time%

I also tried this:
Code: [Select]
@ 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
Title: Re: commands after batch file that pings not working
Post by: Helpmeh on September 05, 2009, 06:10:37 AM
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.
Title: Re: commands after batch file that pings not working
Post by: Two-eyes on September 05, 2009, 06:20:03 AM
if you meant in the wait.bat, it didn't work.  It closed the cmd.
Thanks, though :)
Title: Re: commands after batch file that pings not working
Post by: Helpmeh on September 05, 2009, 06:31:06 AM
Try exit /b then. Try adding PAUSE after each line to see where it's not working (in both batch files).
Title: Re: commands after batch file that pings not working
Post by: Two-eyes on September 05, 2009, 06:47:35 AM
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:
Code: [Select]
@ echo off
echo %time%
pause
wait.bat 3
pause
start cmd.exe
pause
echo %time%

wait.bat:
Code: [Select]
@echo off
ping locahost -n %1 -w 1000 > nul
pause
exit /b

Thanks dude for your patience :)
Title: Re: commands after batch file that pings not working
Post by: Salmon Trout on September 05, 2009, 07:02:28 AM
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)

Code: [Select]
@echo off
batch2.bat
REM this line never executes

right:

Code: [Select]
@echo off
call batch2.bat
REM this line will execute when batch2.bat is finished
Title: Re: commands after batch file that pings not working
Post by: Two-eyes on September 05, 2009, 07:12:33 AM
wooops...that was it...probably skipped lesson 1 ;P

Thanks all

Two-eyes
Title: Re: commands after batch file that pings not working
Post by: Salmon Trout on September 05, 2009, 07:16:43 AM
probably skipped lesson 1

It wasn't you I meant  ;)
Title: Re: commands after batch file that pings not working
Post by: Two-eyes on September 05, 2009, 07:21:31 AM
please do not implicate me in your rivalry.
 ::)
Title: Re: commands after batch file that pings not working
Post by: Salmon Trout on September 05, 2009, 07:28:16 AM
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"?)
Title: Re: commands after batch file that pings not working
Post by: billrich on September 05, 2009, 07:33:09 AM

C:\>type main.bat
Code: [Select]
@echo off
call wait.bat
echo this line will execute when wait.bat is finished

C:\>type  wait.bat
Code: [Select]
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 )
Title: Re: commands after batch file that pings not working
Post by: Helpmeh on September 05, 2009, 07:39:18 AM
The OP was making a sleep command with PING.
Title: Re: commands after batch file that pings not working
Post by: billrich on September 05, 2009, 07:42:54 AM
The OP was making a sleep command with PING.

The sleep.exe  command is better than ping
Title: Re: commands after batch file that pings not working
Post by: Two-eyes on September 05, 2009, 07:43:56 AM
@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
Title: Re: commands after batch file that pings not working
Post by: Salmon Trout on September 05, 2009, 07:45:21 AM
@ST: it's the emails i'll recieve that i'm talking about.

What emails? What are you talking about?
Title: Re: commands after batch file that pings not working
Post by: Helpmeh on September 05, 2009, 07:47:24 AM
@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.
Title: Re: commands after batch file that pings not working
Post by: Two-eyes on September 05, 2009, 07:52:54 AM
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
Title: Re: commands after batch file that pings not working
Post by: Salmon Trout on September 05, 2009, 07:55:06 AM
Just forget bout it

Gladly

 ::)