System.Diagnostics.Process
クラスを使用してプロセスを作成しました。コードはこちら
Process p = new Process()
{
StartInfo = new ProcessStartInfo(@"some.exe")
{
CreateNoWindow = true,
ErrorDialog = false,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
StandardErrorEncoding = Encoding.UTF8,
StandardOutputEncoding = Encoding.UTF8,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
}
};
p.OutputDataReceived += (sender, r) =>
{
Console.WriteLine(r.Data);
};
p.Start();
p.BeginOutputReadLine();
int counter = 0;
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.StandardInput.WriteLine("INPUT" + counter++);
p.WaitForExit();
Console.ReadKey();
}
some.exe im では、実際のコンソール アプリケーションである 2 つのアプリ ドメインを作成しています。AppDomain.ExecuteAsselbly("path to exe")
そのため、プロセスに入力を提供すると、最初にロードされたアプリドメインがすべての入力を取得し、2 番目のアプリドメインはそれを取得しません。
入力を受け取るアプリドメインを決定する方法はありますか? 編集:-
AppDomain という用語がここで間違って使用されていることに突然気付きました。実際に私が言いたいのは、現在のプロセスのどのスレッドが入力を受け取るべきかということです。