From a5cee6e6d5086e9a64bdb3e5284f185d0b57aab2 Mon Sep 17 00:00:00 2001 From: Adam Newgas Date: Sat, 27 Apr 2019 19:05:26 +0100 Subject: [PATCH] Reduce chance of detecting false positives when scanning subprocesses for errors. Fixes #160 --- ElectronNET.CLI/ProcessHelper.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ElectronNET.CLI/ProcessHelper.cs b/ElectronNET.CLI/ProcessHelper.cs index 2eff1a26..11c55c68 100644 --- a/ElectronNET.CLI/ProcessHelper.cs +++ b/ElectronNET.CLI/ProcessHelper.cs @@ -1,11 +1,14 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; +using System.Text.RegularExpressions; namespace ElectronNET.CLI { public class ProcessHelper { + private readonly static Regex ErrorRegex = new Regex(@"\berror\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public static int CmdExecute(string command, string workingDirectoryPath, bool output = true, bool waitForExit = true) { using (Process cmd = new Process()) @@ -44,7 +47,7 @@ public static int CmdExecute(string command, string workingDirectoryPath, bool o // 1 if something fails if (e != null && string.IsNullOrWhiteSpace(e.Data) == false) { - if (e.Data.ToLowerInvariant().Contains("error")) + if (ErrorRegex.IsMatch(e.Data)) { returnCode = 1; } @@ -63,7 +66,7 @@ public static int CmdExecute(string command, string workingDirectoryPath, bool o // 1 if something fails if (e != null && string.IsNullOrWhiteSpace(e.Data) == false) { - if (e.Data.ToLowerInvariant().Contains("error")) + if (ErrorRegex.IsMatch(e.Data)) { returnCode = 1; }