From 909708da297b4ef877b481e36610a61bc475cbcf Mon Sep 17 00:00:00 2001 From: Sebastian Solnica Date: Tue, 26 Feb 2019 16:50:15 +0100 Subject: [PATCH] Errors going to stderr (#8) --- ProcessGovernor/Program.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ProcessGovernor/Program.cs b/ProcessGovernor/Program.cs index f2b460e..8d5b739 100644 --- a/ProcessGovernor/Program.cs +++ b/ProcessGovernor/Program.cs @@ -66,23 +66,23 @@ public static int Main(string[] args) try { procargs = p.Parse(args); } catch (OptionException ex) { - Console.Write("ERROR: invalid argument"); - Console.WriteLine(ex.Message); + Console.Error.Write("ERROR: invalid argument"); + Console.Error.WriteLine(ex.Message); Console.WriteLine(); showhelp = true; } catch (FormatException) { - Console.WriteLine("ERROR: invalid number in one of the constraints"); + Console.Error.WriteLine("ERROR: invalid number in one of the constraints"); Console.WriteLine(); showhelp = true; } catch (ArgumentException ex) { - Console.WriteLine("ERROR: {0}", ex.Message); + Console.Error.WriteLine("ERROR: {0}", ex.Message); Console.WriteLine(); showhelp = true; } if (!showhelp && registryOperation != RegistryOperation.NONE) { if (procargs.Count == 0) { - Console.WriteLine("ERROR: please provide an image name for a process you would like to intercept."); + Console.Error.WriteLine("ERROR: please provide an image name for a process you would like to intercept."); return 1; } SetupRegistryForProcessGovernor(procgov, procargs[0], registryOperation); @@ -90,7 +90,7 @@ public static int Main(string[] args) } if (!showhelp && (procargs.Count == 0 && pid == 0) || (pid > 0 && procargs.Count > 0)) { - Console.WriteLine("ERROR: please provide either process name or PID of the already running process"); + Console.Error.WriteLine("ERROR: please provide either process name or PID of the already running process"); Console.WriteLine(); showhelp = true; } @@ -116,10 +116,10 @@ public static int Main(string[] args) } return procgov.StartProcess(procargs); } catch (Win32Exception ex) { - Console.WriteLine("ERROR: {0} (0x{1:X})", ex.Message, ex.ErrorCode); + Console.Error.WriteLine("ERROR: {0} (0x{1:X})", ex.Message, ex.ErrorCode); return 1; } catch (Exception ex) { - Console.WriteLine("ERROR: {0}", ex.Message); + Console.Error.WriteLine("ERROR: {0}", ex.Message); return 1; } } @@ -273,7 +273,7 @@ public enum RegistryOperation public static void SetupRegistryForProcessGovernor(ProcessGovernor procgov, string appImageExe, RegistryOperation oper) { if (!IsUserAdmin()) { - Console.WriteLine("You must be admin to do that. Run the app from the administrative console."); + Console.Error.WriteLine("You must be admin to do that. Run the app from the administrative console."); return; } // extrace image.exe if path is provided