2016-06-25 18 views
-3

私はコンソールプログラム用の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(); 
    } 
} 

答えて

0

これによれば:https://msdn.microsoft.com/en-us/library/system.diagnostics.process.outputdatareceived(v=vs.110).aspx

OutputDataReceivedイベントは、関連するプロセスが が書き込まれたことを示し

改行文字で終了する行を、リダイレクトされた StandardOutputストリームに渡します。

私は、ASF.exeプログラムの問題は、入力を待つ前に改行文字を送信していないパスワードを求めるプロンプトが表示されることを示唆しています。

ASFプログラムの動作方法を変更したり、別の方法で標準の&エラー出力ストリームを読み込もうとしています。

これはあなたを助けるかもしれない:

https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx

関連する問題