2016-12-22 5 views
0

私は、OutputDataReceivedを使用して、RichTextBoxでプロセスの出力を表示しています。時には、プロセスにユーザー入力が必要な場合があります。ユーザーは新しい行ではなく、同じ行に入力を入力する必要があるため、条件を処理できません。したがって、条件が発生することはありません。例えば入力が必要なときにOutputDataReceivedが停止する

public ASFProcess(ASFui asf, RichTextBox rtb) 
{ 
    _asf = asf; 
    ASF = new Process(); 
    output = rtb; 

    var ASFInfo = new ProcessStartInfo() 
    { 
     Arguments = "--server", 
     CreateNoWindow = true, 
     Domain = "", 
     FileName = Properties.Settings.Default.ASFBinary, 
     LoadUserProfile = false, 
     Password = null, 
     RedirectStandardError = true, 
     RedirectStandardInput = true, 
     RedirectStandardOutput = true, 
     StandardErrorEncoding = Encoding.UTF8, 
     StandardOutputEncoding = Encoding.UTF8, 
     UseShellExecute = false, 
     WindowStyle = ProcessWindowStyle.Hidden 
    }; 

    ASF.StartInfo = ASFInfo; 
    ASF.OutputDataReceived += OutputHandler; 
} 

private void OutputHandler(object sender, DataReceivedEventArgs e) 
{ 
    if (e.Data.EndsWith("input:")) 
    { 
     var result = Interaction.InputBox(e.Data, @"Enter necessary input"); 
     ASF.StandardInput.WriteLine(result); 
     ASF.StandardInput.Flush(); 
    } 

    ... 

} 

This line is printed in the richtextbox, because it doesn't require an input. 
Enter your input: _ (This is when the prompt must be shown) 
This line is never shown because the process is waiting an input. 

感謝。

答えて

0

コンソールで同じことをするのはずっと簡単ですが、それは言われています。

テキストボックスは、追加するすべての文字にイベントをトリガーするため、すべての入力に対してイベントをトリガーするようにはなっていません。

本当にテキストボックスを使用する場合は、テキストボックスの下に「送信」ボタンを追加することをお勧めします。このボタンを使用してイベントをトリガーできます。

OR

カーソルがテキストボックス内にあり、2番目のオプションは、より多くのあなたが望むもののように聞こえる

+0

をEnterキーを押したときにイベントをスローしますようにあなたは、ボタンをバインドすることができますか? –

関連する問題