How to capture error from invoke code activity (exe file) & store it in argument

Main.xaml (14.2 KB)
Program.cs (3.9 KB)
In above workflow i’m adding a sign image to pdf it works fine, but I wants to capture the (error msg / sucess code) from exe file & save it in variable.
I attached Workflow & code file above can anybody suggest me changes in it?

@Anil_G @Sudharsan_Ka @supermanPunch @Kaviyarasu_N @fernando_zuluaga @ppr @Yoichi

Hi @pravin_bindage ,

If you want to capture the Error which might happen in the Invoke Code activity, then you would have to Enclose the Statements in a Try Catch Block and in the Catch you would need to assign the Exception variable outside of the activity using an out argument :

Example :

Catch ex As Exception
    out_Exception = ex
End Try

Here, out_Exception is a System.Exception type argument which has a direction Out

I used invoke to run exe file. If error is in exe file execution then what can we do?


Can you check the following sample? This output stabdard output and standard error of the process.


Dim p As New Process()
p.StartInfo.FileName = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("USERPROFILE"),"AppData\Local\Programs\UiPath\Studio\UiPath.LicenseTool.exe")
p.StartInfo.Arguments = "info"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True


stdout = p.StandardOutput.ReadToEnd()
stderr = p.StandardError.ReadToEnd()
p.Close() (2.6 KB)


1 Like
Dim process As New Process()
process.StartInfo.FileName = Chr(34) + ExePath + Chr(34)
process.StartInfo.Arguments = Chr(34) + InputFile + Chr(34)
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
process.StartInfo.UseShellExecute = False

Dim exitCode As Integer = process.ExitCode
Dim outputMessage As String = process.StandardOutput.ReadToEnd()
Dim errorMessage As String = process.StandardError.ReadToEnd()

If exitCode = 0 Then
    ' Successful execution
    ' Store outputMessage in outputVariable
    outputVariable = outputMessage
    ' Error occurred
    ' Store errorMessage in errorVariable
    errorVariable = errorMessage
End If

Done with this code now it capturing error

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.