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?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
Given this C# program:
Sample runs:
and this VBScript script (reduced to the bare minimum, don't do this in production):
Sample runs:
You'll see
cscript 13921064.vbs nonum & echo %ERRORLEVEL%
is useless tooI'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:
For VB.NET see this MSDN page.
You can do:
As @gideon commented, in your executable you must use
return
statement to return the number.In your script, please read
%ERRORLEVEL%
after calling this executable. That's the place Windows holds the return code.In addition to @gideon you can also set
In other parts of your code and exit directly if something really bad has happened