Help! LPRun.exe exceptions not setting %errorlevel%
I love Linqpad and when I saw LPRun, I thought it should work pretty well for our build scripts. I would love to write the logic for them in C# instead of batch files. However, I have run into a major issue in that LPRun.exe always returns an %errorlevel% of zero when an exception occurs when a script is run.
Here is my script in Linqpad (C# Statements):
As potential solutions to this problem I tried a number of different approaches all with the same result of %errorlevel% still being zero:
Setting Environment.ExitCode
Setting the environment variable explicity:
Returning a value from Main:
Here is my script in Linqpad (C# Statements):
throw new Exception("whoops");Here is the batch file that calls it:
"C:\Program Files (x86)\LINQPad4\LPRun.exe" "c:\Users\user\Documents\LINQPad Queries\TestError.linq" ECHO %errorlevel%Here is the output:
Exception: whoops at UserQuery in c:\Users\user\Documents\LINQPad Queries\TestError.linq:line 3 at LINQPad.ExecutionModel.ClrQueryRunner.Run() at LINQPad.ExecutionModel.Server.RunQuery(QueryRunner runner) C:\Users\user\Documents\LINQPad Queries>ECHO 0 0I would expect the %errorlevel% to be set to some value other than zero (which indicates success). I had previously used scriptcs.exe and .csx files and this was their behavior so I was quite surprised when I switched to lprun.
As potential solutions to this problem I tried a number of different approaches all with the same result of %errorlevel% still being zero:
Setting Environment.ExitCode
Environment.ExitCode = 1;
Setting the environment variable explicity:
Environment.SetEnvironmentVariable("ERRORLEVEL", "1");
Returning a value from Main:
int Main() { return 1; }I guess I can accept that maybe this is a little outside of the original intention of LPRun and maybe Linqpad itself. However, I feel like there ought to be *some* way to return a value to the outside world. Is this something that can be considered a bug and be fixed, or is it just a "we won't support that" situation. I *love* Linqpad, already bought licenses for the build server and everything before discovering this issue (when I noticed our builds weren't working but were reporting success to Jenkins). Anybody have any creative solution that could work for me in the time being?
Comments
You implemented this functionality a while back. The requestor suggested some options.... did you implement them all? If not, which did you implement?
Thanks
User Joe
Environment.Exit(…)
in order to have a more graceful shutdown. Like @jsytniak, I'm wondering what's the status of this? One would imagine that it would be an easy fix so I am surprised to see this still unresolved (3 years on since it was reported).In the 5.35.1 beta, I've also allowed you to return a non-zero value by returning an int value from Main, or by setting Environment.ExitCode.