Results 1 to 8 of 8

Thread: Sleep in Batch File

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Sleep in Batch File

    How can i make a batch file to wait for 10 seconds before cotinuing.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Sleep in Batch File

    You could write a vb program to sleep for 10 seconds, and call it from the batch file. Don't know of any time commands in a batch file. You could have the batch file wait for another process to finish, though.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: Sleep in Batch File

    I used Choice.com till now. But it wasn't ship with xp. So i was hoping someone can tell me of an alternative way.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Sleep in Batch File

    To do what dglienna suggested start a new standard EXE project. Remove the standard Form and add a BAS module instead. Change the startup object of the project to Sub Main and add the following code to the module.
    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    2.  
    3. Public Sub Main()
    4.     If Not IsNumeric(Command$) Then
    5.         MsgBox "Usage: Wait interval" & vbCrLf & vbCrLf & _
    6.          "Interval is a numeric time to wait expressed in milliseconds."
    7.     Else
    8.         Call Sleep(CLng(Command$))
    9.     End If
    10. End Sub
    Save the project as Wait.vbp (or whatever) and compile it. Now in your BAT file you can run this application like this:
    Code:
    @echo off
    echo Wait for 10 seconds
    c:\thePath\Wait.exe 10000
    echo Done!

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: Sleep in Batch File

    I am looking for a way without having to install any app.

    There must be some trick.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Sleep in Batch File

    Well this is a VB forum so why are you asking this question here if you didn't want to use VB to solve it?

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Sleep in Batch File

    I think that MSGBOX might be a bad choice - as if this runs in a .BAT file on a server, for instance, that will pop-up on a screen not being watched...

    Maybe some kind of PRINT statement to the console? Not sure how that works though...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Sleep in Batch File

    Quote Originally Posted by szlamany
    I think that MSGBOX might be a bad choice - as if this runs in a .BAT file on a server, for instance, that will pop-up on a screen not being watched...
    Well, the MsgBox will only appear if you don't pass the interval the app should wait before it exits so if it appears you haven't debugged your BAT file before you put it on the server. But attached is a C program that does exactly the same thing as my above VB code except that it's a console app.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width