Forum Discussion

jyothinb's avatar
jyothinb
Contributor
8 years ago

How to wait until that process completes in the command prompt

Hi, My developers developed a process to clean the data. It runs long time when there is lot of data. I would like to close the process after it completely deletes all data. How can I tell TC to wait until that last line appears and then close it. Please see the screen shot.

 

http://screencast.com/t/A0LSIjWv

5 Replies

    • joseph_michaud's avatar
      joseph_michaud
      Moderator

      Perhaps you could examine the text of the window in a loop looking for what you want....

      • jyothinb's avatar
        jyothinb
        Contributor

        My question is,  how to write a code to look for that last line in the screen shot. TC is not recognizing the text.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Assuming that the process exits when done, you may consider the function that was created ages ago:) (VBScript) :

    '-----------------------------------------------------------------------------
    
    ' Function starts program and waits until it finishes
    Function ExecAndWaitForEnd(ByVal strProg, ByVal strArgs)
        Dim WshShell
        Dim oExec
        Dim strCommand
        Dim allOutput
    
        ExecAndWaitForEnd = -1
    
    '    strProg = Utilities.AnsiQuotedStr(Trim(strProg), """")
        strProg = Trim(strProg)
        If (Left(strProg, 1) <> """") Then
            strProg = """" & strProg & """"
        End If
    
        strCommand = strProg & " " & strArgs
    '    oLogFile.WriteLineToLog (cLOGSTRINFO & "Executing: " & strCommand & "...")
        Set WshShell = CreateObject("WScript.Shell")
        Set oExec = WshShell.Exec(strCommand)
    
        Do While oExec.Status = 0
            BuiltIn.Delay 500
        Loop
    
        allOutput = ReadAllFromAny(oExec)
        Log.Message "ExecAndWaitForEnd(): Call exit code=" & oExec.ExitCode, _
                "CmdLine: " & strCommand & vbCrLf & vbCrLf & "Output: " & allOutput
    
        ExecAndWaitForEnd = oExec.ExitCode
    '    oLogFile.WriteLineToLog (cLOGSTRINFO & "Done. (Return code = " & oExec.ExitCode & ")")
    
        Set oExec = Nothing
        Set WshShell = Nothing
    End Function
    '-----------------------------------------------------------------------------
    
    Function ReadAllFromAny(ByRef oExec)
    
         If Not oExec.StdOut.AtEndOfStream Then
              ReadAllFromAny = oExec.StdOut.ReadAll
              Exit Function
         End If
    
         If Not oExec.StdErr.AtEndOfStream Then
              ReadAllFromAny = cLOGSTRERROR & "STDERR: " & oExec.StdErr.ReadAll
              Exit Function
         End If
    
         ReadAllFromAny = -1
    End Function
    '-----------------------------------------------------------------------------
    

     

    Call sample:

    Call ExecAndWaitForEnd("cmd.exe", _
          "/c copy /y " + Utilities.AnsiQuotedStr(strSourceDB, """") + " " + _
          Utilities.AnsiQuotedStr(strTargetDB, """"));