I have created a Console application for validating a function and this application i need to execute by using vbscript. After executing this exe i want to return an exit code whether the function return success or not. How can i return a status or exit code in .net?
Exit Code Of Windowed Application # Windows CMD C:\> start /wait app.exe C:\> if %ErrorLevel% equ 0 (echo True) else (echo False) # Windows PowerShell PS C:\> app.exe PS C:\> $?
Use the command Exit $LASTEXITCODE at the end of the powershell script to return the error codes from the powershell script. $LASTEXITCODE holds the last error code in the powershell script.
Each process has an exit code that can be accessed by other processes and can be used to indicate success or failure. A process sets an exit code in the value returned from either WinMain or the "C" main function. A process could, for example, return 0 to indicate success or a non-zero value indicating an error code.
In addition to @gideon you can also set
Environment.ExitCode = theExitCode;
In other parts of your code and exit directly if something really bad has happened
I'm going to assume you're writing either C# or VB.NET. In either case usually people have a Main function that returns nothing, but you can change this to return an integer to represent the exit code.
For C# see this MSDN page.
You can do:
static int Main()
{
//...
return 0;
}
For VB.NET see this MSDN page.
You can do:
Module mainModule
Function Main() As Integer
'....
'....
Return returnValue
End Function
End Module
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With