C# 过程输出不';不要写最后一行

C# 过程输出不';不要写最后一行,c#,process,C#,Process,我正在为控制台程序制作GUI。有时它需要输入密码,因此如果输出包含“密码”,则会打开一个对话框 问题是,输出没有打印“输入密码”这一行,而是在运行控制台时打印 开始… 正在读取配置… 输入您的密码:根据以下内容: OutputDataReceived事件表示关联的进程 写了一篇 行,以换行符结尾,指向其重定向 标准输出流 因此,我认为ASF.exe程序的问题在于,在提示输入密码的行中,它没有在预期输入之前发送换行符 我建议改变ASF程序的工作方式,或者尝试以另一种方式读取标准和错误输出流 这可能

我正在为控制台程序制作GUI。有时它需要输入密码,因此如果输出包含“密码”,则会打开一个对话框

问题是,输出没有打印“输入密码”这一行,而是在运行控制台时打印

开始…
正在读取配置…
输入您的密码:根据以下内容:

OutputDataReceived事件表示关联的进程 写了一篇

行,以换行符结尾,指向其重定向 标准输出流

因此,我认为ASF.exe程序的问题在于,在提示输入密码的行中,它没有在预期输入之前发送换行符

我建议改变ASF程序的工作方式,或者尝试以另一种方式读取标准和错误输出流

这可能会帮助您:

this.ASFProcess.StartInfo.Arguments = "--server";
this.ASFProcess.StartInfo.CreateNoWindow = true;
this.ASFProcess.StartInfo.Domain = "";
this.ASFProcess.StartInfo.FileName = "ASF.exe";
this.ASFProcess.StartInfo.LoadUserProfile = false;
this.ASFProcess.StartInfo.Password = null;
this.ASFProcess.StartInfo.RedirectStandardError = true;
this.ASFProcess.StartInfo.RedirectStandardInput = true;
this.ASFProcess.StartInfo.RedirectStandardOutput = true;
this.ASFProcess.StartInfo.StandardErrorEncoding = null;
this.ASFProcess.StartInfo.StandardOutputEncoding = null;
this.ASFProcess.StartInfo.UserName = "";
this.ASFProcess.StartInfo.UseShellExecute = false;
this.ASFProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
this.ASFProcess.SynchronizingObject = this;
this.ASFProcess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(this.ASFProcess_OutputDataReceived);
this.ASFProcess.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(this.ASFProcess_ErrorDataReceived);
private void BackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
    ASFProcess.Start();
    ASFProcess.BeginOutputReadLine();
    ASFProcess.BeginErrorReadLine();
    ASFProcess.WaitForExit();
}

private void ASFProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    rtbOutput.AppendText(e.Data + Environment.NewLine);
    rtbOutput.SelectionStart = rtbOutput.Text.Length;
    rtbOutput.ScrollToCaret();
    if (e.Data.Contains("password"))
    {
        var enterPassword = new EnterPassword();
        enterPassword.ShowDialog();
    }
}