Results 1 to 2 of 2

Thread: Wait till Shell operation is complete

  1. #1

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545

    Wait till Shell operation is complete

    Hi,

    I am shelling to another application to process a file

    Once this processing is complete (typically a few minutes), I need to shell out to another application.

    Currently, I have the two shell commands one after another, but they both get called at the same time.

    How do you determine when the first shell operation is complete before staring another one??????

    Thanx for any suggestions!

  2. #2
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Use this in a module
    VB Code:
    1. Private Type STARTUPINFO
    2.     cb As Long
    3.     lpReserved As String
    4.     lpDesktop As String
    5.     lpTitle As String
    6.     dwX As Long
    7.     dwY As Long
    8.     dwXSize As Long
    9.     dwYSize As Long
    10.     dwXCountChars As Long
    11.     dwYCountChars As Long
    12.     dwFillAttribute As Long
    13.     dwFlags As Long
    14.     wShowWindow As Integer
    15.     cbReserved2 As Integer
    16.     lpReserved2 As Long
    17.     hStdInput As Long
    18.     hStdOutput As Long
    19.     hStdError As Long
    20. End Type
    21.  
    22. Private Type PROCESS_INFORMATION
    23.     hProcess As Long
    24.     hThread As Long
    25.     dwProcessId As Long
    26.     dwThreadID As Long
    27. End Type
    28.  
    29. Const NORMAL_PRIORITY_CLASS = &H20
    30. Const IDLE_PRIORITY_CLASS = &H40
    31. Const HIGH_PRIORITY_CLASS = &H80
    32.  
    33. Private Declare Function WaitForSingleObject Lib _
    34.     "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
    35.     As Long) As Long
    36.  
    37. Private Declare Function CreateProcessA Lib "kernel32" _
    38.     (ByVal lpApplicationName As Long, ByVal lpCommandLine As _
    39.     String, ByVal lpProcessAttributes As Long, ByVal _
    40.     lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
    41.     ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
    42.     ByVal lpCurrentDirectory As Long, lpStartupInfo As _
    43.     STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
    44.     As Long
    45.  
    46. Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) _
    47.     As Long
    48.  
    49. Public Sub ShellNWait(CommandLine As String, Optional WaitForMilliseconds As Long = -1&, Optional Priority As Long = NORMAL_PRIORITY_CLASS)
    50.     Dim proc As PROCESS_INFORMATION
    51.     Dim Start As STARTUPINFO
    52.     Dim lRet As Long
    53. On Error Resume Next
    54.  
    55.     'Initialize the STARTUPINFO structure:
    56.     Start.cb = Len(Start)
    57.    
    58.     'Start the shelled application:
    59.     lRet = CreateProcessA(0&, CommandLine, 0&, 0&, 1&, _
    60.     Priority, 0&, 0&, Start, proc)
    61.    
    62.     'Wait for the shelled application to finish:
    63.     'use -1 to specify no "timeout" length.
    64.     lRet = WaitForSingleObject(proc.hProcess, WaitForMilliseconds)
    65.     lRet = CloseHandle(proc.hProcess)
    66.    
    67. End Sub
    And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.

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