私はコンソールプログラム用のGUIを作っています。時にはパスワードのような入力が必要なので、出力に "password"が含まれているとダイアログが開きます。プロセス出力は最後の行を書きません
問題は、出力に "パスワードを入力してください"という行が表示されず、コンソールが実行されていることです。コンフィギュレーションを読む
オープニング...
...
パスワードを入力します:< - これは、GUIコンソールに表示されますが、ありません。
プロセス:
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();
}
}