void RunSubprocess(string prog, string[] argv, StringBuilder stdout, StringBuilder stderr) { var p = new Process(); p.StartInfo = new ProcessStartInfo(prog, ArgumentUtils.JoinAguments(argv)); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.ErrorDataReceived += (o, a) => { if (a.Data != null) { stderr.AppendLine(a.Data); } }; p.OutputDataReceived += (o, a) => { if (a.Data != null) { stdout.AppendLine(a.Data); } }; p.Start(); p.BeginErrorReadLine(); p.BeginOutputReadLine(); p.WaitForExit(); }
public void EscapeSpaces() { Assert.AreEqual("\\\"foo\\\" bar \"baz spaces\" \"bar spaces\"", ArgumentUtils.JoinAguments(new string[] { "\"foo\"", "bar", "baz spaces", "bar spaces" })); Assert.AreEqual("\" \" \"x x x\"", ArgumentUtils.JoinAguments(new string[] { " ", "x x x" })); }
public void EscapeSlashes() { Assert.AreEqual("foo\\bar\\file.c", ArgumentUtils.JoinAguments(new string[] { "foo\\bar\\file.c" })); }