public static CmdResult MatchResultToCmdResult(byte[] resultBytes, Encoding encode) { string result = GetResultFromInterval(resultBytes, encode); string pattern = @"(?<cmd>.*)\[S\]\s*(?<curdir>.*?)\s*\[E\]\s*(?<error>.*)"; Regex regex = new Regex(pattern, RegexOptions.Singleline); Match m = regex.Match(result); if (!m.Success) { throw new ResponseCustomException(ExceptionTitle.MatchResultFailed.ToString(), "match result failed", result); } else { //存在一种情况,错误信息会跟在[E]之后 string cmd = m.Groups["cmd"].Value + m.Groups["error"].Value; string curdir = m.Groups["curdir"].Value; CmdResult cmdResult = new CmdResult(); cmdResult.Result = cmd; cmdResult.CurrentDir = curdir; return(cmdResult); } }
public static CmdResult MatchResultToCmdResult(byte[] resultBytes, Encoding encode) { string result = GetResultFromInterval(resultBytes, encode); string pattern = @"(?<cmd>.*)\[S\]\s*(?<curdir>.*?)\s*\[E\]\s*(?<error>.*)"; Regex regex = new Regex(pattern, RegexOptions.Singleline); Match m = regex.Match(result); if (!m.Success) { throw new ResponseCustomException(ExceptionTitle.MatchResultFailed.ToString(), "match result failed", result); } else { //存在一种情况,错误信息会跟在[E]之后 string cmd = m.Groups["cmd"].Value + m.Groups["error"].Value; string curdir = m.Groups["curdir"].Value; CmdResult cmdResult = new CmdResult(); cmdResult.Result = cmd; cmdResult.CurrentDir = curdir; return cmdResult; } }