Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: commands after batch file that pings not working  (Read 5950 times)

0 Members and 1 Guest are viewing this topic.

Two-eyes

    Topic Starter


    Intermediate
  • Thanked: 4
    commands after batch file that pings not working
    « 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
    Quote
    I believe the bushes in my yard will BURN before God picks up a PC to send a message


    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: commands after batch file that pings not working
    « Reply #1 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.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    Two-eyes

      Topic Starter


      Intermediate
    • Thanked: 4
      Re: commands after batch file that pings not working
      « Reply #2 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 :)
      Quote
      I believe the bushes in my yard will BURN before God picks up a PC to send a message


      Helpmeh



        Guru

      • Roar.
      • Thanked: 123
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 8
      Re: commands after batch file that pings not working
      « Reply #3 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).
      Where's MagicSpeed?
      Quote from: 'matt'
      He's playing a game called IRL. Great graphics, *censored* gameplay.

      Two-eyes

        Topic Starter


        Intermediate
      • Thanked: 4
        Re: commands after batch file that pings not working
        « Reply #4 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 :)
        Quote
        I believe the bushes in my yard will BURN before God picks up a PC to send a message


        Salmon Trout

        • Guest
        Re: commands after batch file that pings not working
        « Reply #5 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

        Two-eyes

          Topic Starter


          Intermediate
        • Thanked: 4
          Re: commands after batch file that pings not working
          « Reply #6 on: September 05, 2009, 07:12:33 AM »
          wooops...that was it...probably skipped lesson 1 ;P

          Thanks all

          Two-eyes
          Quote
          I believe the bushes in my yard will BURN before God picks up a PC to send a message


          Salmon Trout

          • Guest
          Re: commands after batch file that pings not working
          « Reply #7 on: September 05, 2009, 07:16:43 AM »
          probably skipped lesson 1

          It wasn't you I meant  ;)

          Two-eyes

            Topic Starter


            Intermediate
          • Thanked: 4
            Re: commands after batch file that pings not working
            « Reply #8 on: September 05, 2009, 07:21:31 AM »
            please do not implicate me in your rivalry.
             ::)
            Quote
            I believe the bushes in my yard will BURN before God picks up a PC to send a message


            Salmon Trout

            • Guest
            Re: commands after batch file that pings not working
            « Reply #9 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"?)

            billrich

            • Guest
            Re: commands after batch file that pings not working
            « Reply #10 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 )

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: commands after batch file that pings not working
            « Reply #11 on: September 05, 2009, 07:39:18 AM »
            The OP was making a sleep command with PING.
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            billrich

            • Guest
            Re: commands after batch file that pings not working
            « Reply #12 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

            Two-eyes

              Topic Starter


              Intermediate
            • Thanked: 4
              Re: commands after batch file that pings not working
              « Reply #13 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
              Quote
              I believe the bushes in my yard will BURN before God picks up a PC to send a message


              Salmon Trout

              • Guest
              Re: commands after batch file that pings not working
              « Reply #14 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?