【发布时间】:2011-06-27 17:06:05
【问题描述】:
对于vsinstr -coverage hello.exe,我可以使用如下C#代码。
Process p = new Process();
StringBuilder sb = new StringBuilder("/COVERAGE ");
sb.Append("hello.exe");
p.StartInfo.FileName = "vsinstr.exe";
p.StartInfo.Arguments = sb.ToString();
p.Start();
p.WaitForExit();
出现错误时,我收到错误消息:Error VSP1018: VSInstr does not support processing binaries that are already instrumented.。
如何使用 C# 获取此错误消息?
已解决
我可以从答案中得到错误信息。
using System;
using System.Text;
using System.Diagnostics;
// You must add a reference to Microsoft.VisualStudio.Coverage.Monitor.dll
namespace LvFpga
{
class Cov2xml
{
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
StringBuilder sb = new StringBuilder("/COVERAGE ");
sb.Append("helloclass.exe");
p.StartInfo.FileName = "vsinstr.exe";
p.StartInfo.Arguments = sb.ToString();
p.Start();
string stdoutx = p.StandardOutput.ReadToEnd();
string stderrx = p.StandardError.ReadToEnd();
p.WaitForExit();
Console.WriteLine("Exit code : {0}", p.ExitCode);
Console.WriteLine("Stdout : {0}", stdoutx);
Console.WriteLine("Stderr : {0}", stderrx);
}
}
}
【问题讨论】:
-
当心,正如@SliverNinja 在下面的评论中所说,阅读 p.StandardOutput.ReadToEnd() 和 p.StandardError.ReadToEnd() 可能会死锁。