如何获得在C#中的错误信息 [英] How to get the error message with C#

查看:213
本文介绍了如何获得在C#中的错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关 vsinstr -coverage文件hello.exe ,我可以使用C#代码如下:

 进程p =新工艺(); 
StringBuilder的SB =新的StringBuilder(/覆盖);
sb.Append(文件hello.exe);
p.StartInfo.FileName =vsinstr.exe;
p.StartInfo.Arguments = sb.ToString();
p.Start();
p.WaitForExit();

当有一个错误,我得到的错误消息:错误VSP1018:VSInstr不支持已经仪表处理的二进制文件。



我怎样才能用C#此错误消息?



解决


$ ; b $ b

我能得到答案的错误信息

 使用系统; 
使用System.Text;使用System.Diagnostics程序
;

//您必须添加一个引用Microsoft.VisualStudio.Coverage.Monitor.dll

命名空间LvFpga
{
类Cov2xml
{
静态无效的主要(字串[] args)
{
进程p =新工艺();
p.StartInfo.RedirectStandardOutput = TRUE;
p.StartInfo.RedirectStandardError = TRUE;
p.StartInfo.UseShellExecute = FALSE;

StringBuilder的SB =新的StringBuilder(/覆盖);
sb.Append(helloclass.exe);
p.StartInfo.FileName =vsinstr.exe;
p.StartInfo.Arguments = sb.ToString();
p.Start();

串stdoutx = p.StandardOutput.ReadToEnd();
串stderrx = p.StandardError.ReadToEnd();
p.WaitForExit();

Console.WriteLine(退出代码:{0},p.ExitCode);
Console.WriteLine(标准输出:{0},stdoutx);
Console.WriteLine(标准错误:{0},stderrx);
}
}
}


解决方案

您需要重定向标准输出或标准错误。下面是标准输出代码示例:

 进程p =新工艺(); 
p.StartInfo.FileName =用hello.exe;
p.StartInfo.RedirectStandardOutput = TRUE;
p.StartInfo.UseShellExecute = FALSE;
p.Start();
字符串标准输出= p.StandardOutput.ReadToEnd();
p.WaitForExit();


For vsinstr -coverage hello.exe, I can use the C# code as follows.

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();

When there's an error, I get the error message : Error VSP1018: VSInstr does not support processing binaries that are already instrumented..

How can I get this error message with C#?

SOLVED

I could get the error messages from the answers.

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);
        }
    }
}

解决方案

You need to redirect the standard output or standard error. Here's a code sample for stdout:

Process p = new Process();
p.StartInfo.FileName = "hello.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
string stdout = p.StandardOutput.ReadToEnd(); 
p.WaitForExit();

这篇关于如何获得在C#中的错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆