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.
感謝。
をEnterキーを押したときにイベントをスローしますようにあなたは、ボタンをバインドすることができますか? –