| ■No19090 (れい さん) に返信
>>.NET Framework 1.1 でもできる範囲のコードで。
>
> いやそのコードはマルチスレッドですから:D
new Thread() してなければ OK だっ!
>>しかし出力は細切れになってしまう。
>
> 素直にStreamReaderとWaitHandle使いましょうよ
それでもいいのか。
StreamReader を使うというのは良くわからんが。
というわけで第三弾。
using (Process p = new Process())
{
p.StartInfo.FileName = "ping.exe";
p.StartInfo.Arguments = "127.0.0.1";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.Start();
while (! p.HasExited)
{
byte[] outputBuffer = new byte[1024];
IAsyncResult result = p.StandardOutput.BaseStream.BeginRead(outputBuffer, 0, outputBuffer.Length, null, null);
result.AsyncWaitHandle.WaitOne();
int count = p.StandardOutput.BaseStream.EndRead(result);
string output = p.StandardOutput.CurrentEncoding.GetString(outputBuffer, 0, count);
Console.Write(output);
}
}
Console.WriteLine();
Console.WriteLine("Complete");
> string output = Console.OutputEncoding.GetString(aa.buffer, 0, count);
>
> ここはダメですねぇ。
> GetDecoderしてDecoder取っておかないと、文字が化けちゃいます。
え、そうなの? |