【问题标题】:no output in being received when starting a process through System.Diagnostics.Process - c#通过 System.Diagnostics.Process 启动进程时没有接收到输出 - c#
【发布时间】:2012-06-26 18:42:22
【问题描述】:

我正在 c# 中使用 System.DIagnostics.Process 创建一个进程
我创建了一个类 CCProcess 继承自 Process
问题是 ErrorDataRecieved OR OutputDataReceived 没有被解雇.. 这是我的代码

public CCProcess(string executablePath, string[] parameters, CCProcessInfo processInfo)
        {
            this.ProcessInfo = processInfo;
            this.OutputMessages = new List<ProcessOutputMessage>();
            this.ProcessId = Guid.NewGuid().ToString();

            base.EnableRaisingEvents = true;
            this.StartInfo = new ProcessStartInfo(executablePath)
            {
                Arguments = string.Join(" ", parameters.Select(s => string.Format("\"{0}\"", s))),
                CreateNoWindow = true,
                ErrorDialog = false,
                RedirectStandardError = true,
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                StandardErrorEncoding = Encoding.UTF8,
                StandardOutputEncoding = Encoding.UTF8,
                WindowStyle = ProcessWindowStyle.Hidden,
                UseShellExecute = false
            };

            this.ErrorDataReceived += (sender, e) =>
            {
                this.OutputMessages.Add(new ProcessOutputMessage() { Message = e.Data, Type = OutputType.Error });
                if (this.ErrorData_Recieved != null&&!string.IsNullOrEmpty(e.Data))
                {
                    this.ProcessInfo.LastResponseFromProcess = DateTime.Now;
                    this.ErrorData_Recieved(e.Data);
                }
            };

            this.OutputDataReceived += (sender, e) =>
            {
                this.OutputMessages.Add(new ProcessOutputMessage() { Message = e.Data, Type = OutputType.Output });
                if (OutputData_Recieved != null && !string.IsNullOrEmpty(e.Data))
                {
                    this.ProcessInfo.LastResponseFromProcess = DateTime.Now;
                    OutputData_Recieved(e.Data);
                }
            };
        }

我做错了什么?
提供的代码是类CCProcess的构造函数

【问题讨论】:

  • 为什么要投反对票? 4 年前我已经回答了一个完整的问题?

标签: c#-4.0 process system.diagnostics


【解决方案1】:

哦,我讨厌这个..在这里发布问题然后回答他们..无论如何
我错过了一个基本的东西
Process.BeginOutputReadLine()
因为这个浪费了2个小时 更多关于这里的信息
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.beginoutputreadline

【讨论】:

    猜你喜欢
    • 2013-10-09
    • 2021-09-03
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-25
    • 2015-04-07
    相关资源
    最近更新 更多