From 7ea448d967c29a30e5025948e2995d00105ee245 Mon Sep 17 00:00:00 2001 From: Asier Llano Date: Wed, 9 Jul 2025 18:48:39 +0200 Subject: [PATCH] errorlevel mantainance after postcommands The errorlevel was only mantained after the "pause" command, but any postcommands (like popd) will avoid errorlevel mantainance. Make this small change to mantain the error level post command properly. --- src/gsudo/Helpers/CommandToRunAdapter.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gsudo/Helpers/CommandToRunAdapter.cs b/src/gsudo/Helpers/CommandToRunAdapter.cs index 209b756b..49d263b4 100644 --- a/src/gsudo/Helpers/CommandToRunAdapter.cs +++ b/src/gsudo/Helpers/CommandToRunAdapter.cs @@ -397,10 +397,7 @@ internal void Build() if (keepWindowOpen && !IsWindowsApp) { - // Using "`& pause " makes cmd eat the exit code - postCommands.Add("set errl = !ErrorLevel!"); postCommands.Add("pause"); - postCommands.Add("exit /b !errl!"); } string startupFolder = InputArguments.StartingDirectory ?? Environment.CurrentDirectory; @@ -419,6 +416,12 @@ internal void Build() if (mustWrap || preCommands.Any() || postCommands.Any()) { + if (postCommands.Any()) + { + // Any post command will eat the exit code, we need to mantain + postCommands.Insert(0, "set errl = !ErrorLevel!"); + postCommands.Add("exit /b !errl!"); + } var all = preCommands .Concat(new[] { string.Join(" ", command) }) .Concat(postCommands);