public void NoOutput() { ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = Path.GetDirectoryName(GetConsoleAppFileName()); runner.Start(GetConsoleAppFileName()); runner.WaitForExit(); Assert.IsFalse(runner.IsRunning, "IsRunning should be false."); Assert.AreEqual(0, runner.ExitCode, "Exit code is incorrect."); Assert.AreEqual(String.Empty, runner.StandardOutput, "Should not be any output."); Assert.AreEqual(String.Empty, runner.StandardError, "Should not be any error output."); }
public void NonZeroExitCode() { ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = Path.GetDirectoryName(GetConsoleAppFileName()); int expectedExitCode = 1; Assert.IsFalse(runner.IsRunning, "IsRunning should be false."); runner.Start(GetConsoleAppFileName(), String.Concat("-exitcode:", expectedExitCode.ToString())); runner.WaitForExit(); Assert.AreEqual(expectedExitCode, runner.ExitCode, "Exit code is incorrect."); Assert.IsFalse(runner.IsRunning, "IsRunning should be false."); }
public void SingleLineOfOutput() { ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = Path.GetDirectoryName(GetConsoleAppFileName()); string echoText = "Test"; string expectedOutput = String.Concat(echoText, "\r\n"); runner.Start(GetConsoleAppFileName(), String.Concat("-echo:", echoText)); runner.WaitForExit(); Assert.IsFalse(runner.IsRunning, "IsRunning should be false."); Assert.AreEqual(0, runner.ExitCode, "Exit code is incorrect."); Assert.AreEqual(expectedOutput, runner.StandardOutput, "Should have some output."); Assert.AreEqual(String.Empty, runner.StandardError, "Should not be any error output."); }
bool Get32BitFlags(string assembly) { assembly = Path.Combine(binPath, assembly); string corflags = FileUtility.GetSdkPath("corflags.exe"); Assert.IsNotNull(corflags, "corflags.exe not found, this test requires the .NET SDK!"); ProcessRunner pr = new ProcessRunner(); Console.WriteLine(corflags + " \"" + assembly + "\""); pr.Start(corflags, "\"" + assembly + "\""); if (!pr.WaitForExit(5000)) { pr.Kill(); throw new InvalidOperationException("Timeout running corflags"); } else { Console.WriteLine(pr.StandardOutput); Match m = Regex.Match(pr.StandardOutput, @"32BIT\s*:\s*([01])"); if (m.Success) { return m.Groups[1].Value == "1"; } else { throw new InvalidOperationException("Invalid corflags output"); } } }
internal static string GetBlobHash(string gitExe, string fileName) { if (!File.Exists(fileName)) return null; ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = Path.GetDirectoryName(fileName); runner.Start(gitExe, "ls-tree HEAD " + Path.GetFileName(fileName)); string blobHash = null; runner.OutputLineReceived += delegate(object sender, LineReceivedEventArgs e) { string[] parts = e.Line.Split(new[] { " ", "\t" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length >= 3) { if (parts[2].Length == 40) blobHash = parts[2]; } }; runner.WaitForExit(); return blobHash; }
static void GitGetFiles(string wcRoot, GitStatusSet statusSet) { ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = wcRoot; runner.LogStandardOutputAndError = false; runner.OutputLineReceived += delegate(object sender, LineReceivedEventArgs e) { if (!string.IsNullOrEmpty(e.Line)) { statusSet.AddEntry(e.Line, GitStatus.OK); } }; string command = "git ls-files"; bool hasErrors = false; runner.ErrorLineReceived += delegate(object sender, LineReceivedEventArgs e) { if (!hasErrors) { hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> " + command); } GitMessageView.AppendLine(e.Line); }; runner.Start("cmd", "/c " + command); runner.WaitForExit(); }
static void GitGetStatus(string wcRoot, GitStatusSet statusSet) { string command = "git status --porcelain --untracked-files=no"; bool hasErrors = false; ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = wcRoot; runner.LogStandardOutputAndError = false; runner.OutputLineReceived += delegate(object sender, LineReceivedEventArgs e) { if (!string.IsNullOrEmpty(e.Line)) { Match m = statusParseRegex.Match(e.Line); if (m.Success) { statusSet.AddEntry(m.Groups[2].Value, StatusFromText(m.Groups[1].Value)); } else { if (!hasErrors) { hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> " + command); } GitMessageView.AppendLine("unknown output: " + e.Line); } } }; runner.ErrorLineReceived += delegate(object sender, LineReceivedEventArgs e) { if (!hasErrors) { hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> " + command); } GitMessageView.AppendLine(e.Line); }; runner.Start("cmd", "/c " + command); runner.WaitForExit(); }
private static void GitGetFiles(string wcRoot, GitStatusSet statusSet) { var git = Git.FindGit(); if (git == null) return; var runner = new ProcessRunner(); runner.WorkingDirectory = wcRoot; runner.LogStandardOutputAndError = false; runner.OutputLineReceived += delegate (object sender, LineReceivedEventArgs e) { if (!string.IsNullOrEmpty(e.Line)) { statusSet.AddEntry(e.Line, GitStatus.OK); } }; var command = "ls-files"; var hasErrors = false; runner.ErrorLineReceived += delegate (object sender, LineReceivedEventArgs e) { if (!hasErrors) { hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> git " + command); } GitMessageView.AppendLine(e.Line); }; runner.Start(git, command); runner.WaitForExit(); }
private static void GitGetStatus(string wcRoot, GitStatusSet statusSet) { var git = Git.FindGit(); if (git == null) return; var command = "status --porcelain --untracked-files=no"; var hasErrors = false; var runner = new ProcessRunner(); runner.WorkingDirectory = wcRoot; runner.LogStandardOutputAndError = false; runner.OutputLineReceived += delegate (object sender, LineReceivedEventArgs e) { if (!string.IsNullOrEmpty(e.Line)) { var m = StatusParseRegex.Match(e.Line); if (m.Success) { statusSet.AddEntry(m.Groups[2].Value, StatusFromText(m.Groups[1].Value)); } else { if (!hasErrors) { // in front of first output line, print the command line we invoked hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> git " + command); } GitMessageView.AppendLine("unknown output: " + e.Line); } } }; runner.ErrorLineReceived += delegate (object sender, LineReceivedEventArgs e) { if (!hasErrors) { hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> git " + command); } GitMessageView.AppendLine(e.Line); }; runner.Start(git, command); runner.WaitForExit(); }
string GetBlobHash(string fileName) { ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = Path.GetDirectoryName(fileName); runner.Start("cmd", "/c git ls-tree HEAD " + Path.GetFileName(fileName)); runner.WaitForExit(); string output = runner.StandardOutput.Trim(); string[] parts = output.Split(new[] { " ", "\t" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length < 3) return null; return parts[2]; }
public void LargeAmountOfOutput() { ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = Path.GetDirectoryName(GetConsoleAppFileName()); string filename = "test.txt"; string fullFilename = Path.Combine(runner.WorkingDirectory, filename); try { string outputText = GetOutputText(); CreateTextFile(fullFilename, outputText); runner.Start(GetConsoleAppFileName(), String.Concat("-file:", filename)); bool exited = runner.WaitForExit(5000); Assert.IsTrue(exited, "App did not exit."); Assert.IsFalse(runner.IsRunning, "IsRunning should be false."); Assert.AreEqual(0, runner.ExitCode, "Exit code is incorrect."); Assert.AreEqual(outputText, runner.StandardOutput, "Should have some output."); Assert.AreEqual(String.Empty, runner.StandardError, "Should not be any error output."); } finally { if (File.Exists(fullFilename)) { File.Delete(fullFilename); } } }
static void GitGetStatus(string wcRoot, GitStatusSet statusSet) { string command = "git status --porcelain --untracked-files=no"; bool hasErrors = false; ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = wcRoot; runner.LogStandardOutputAndError = false; string commandPrompt = wcRoot + ">@"; // C:\work\SD>@git.exe %* runner.OutputLineReceived += delegate(object sender, LineReceivedEventArgs e) { if (!string.IsNullOrEmpty(e.Line)) { Match m = statusParseRegex.Match(e.Line); if (m.Success) { statusSet.AddEntry(m.Groups[2].Value, StatusFromText(m.Groups[1].Value)); } else if (!e.Line.StartsWith(commandPrompt, StringComparison.Ordinal)) { // Suppress "unknown output" produced by git.cmd when git is installed // in the PATH but the git unix tools aren't if (!hasErrors) { // in front of first output line, print the command line we invoked hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> " + command); } GitMessageView.AppendLine("unknown output: " + e.Line); } } }; runner.ErrorLineReceived += delegate(object sender, LineReceivedEventArgs e) { if (!hasErrors) { hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> " + command); } GitMessageView.AppendLine(e.Line); }; runner.Start("cmd", "/c " + command); runner.WaitForExit(); }