C# と VB.NET の質問掲示板

ASP.NET、C++/CLI、Java 何でもどうぞ

ログ内検索
  • キーワードを複数指定する場合は 半角スペース で区切ってください。
  • 検索条件は、(AND)=[A かつ B] (OR)=[A または B] となっています。
  • [返信]をクリックすると返信ページへ移動します。
キーワード/ 検索条件 /
検索範囲/ 強調表示/ ON (自動リンクOFF)
結果表示件数/ 記事No検索/ ON
大文字と小文字を区別する

No.19095 の関連記事表示

<< 0 >>
■19095  Re[3]: Processの標準出力をリアルタイム取得
□投稿者/ シャノン -(2008/05/20(Tue) 11:35:57)
    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取っておかないと、文字が化けちゃいます。
    
    え、そうなの?
記事No.19072 のレス /過去ログ37より / 関連記事表示
削除チェック/



<< 0 >>

パスワード/

- Child Tree -