コマンドプロンプトで実行する場合
netstat -an | find /c /v ""
C# で実行する場合
ProcessStartInfo psInfo1 = new ProcessStartInfo(); psInfo1.FileName = "netstat"; psInfo1.Arguments = "-an"; psInfo1.CreateNoWindow = true; psInfo1.UseShellExecute = false; psInfo1.RedirectStandardOutput = true; Process p1 = Process.Start(psInfo1); ProcessStartInfo psInfo2 = new ProcessStartInfo(); psInfo2.FileName = "find "; psInfo2.Arguments = "/c /v \"\""; psInfo2.CreateNoWindow = true; psInfo2.UseShellExecute = false; psInfo2.RedirectStandardOutput = true; psInfo2.RedirectStandardInput = true; Process p2 = Process.Start(psInfo2); string output1 = p1.StandardOutput.ReadToEnd(); StreamWriter p2Writer = p2.StandardInput; p2Writer.AutoFlush = true; p2Writer.Write(output1); p2Writer.Close(); string output2 = p2.StandardOutput.ReadToEnd();