如何从Winform C#执行linux命令?

时间:2016-08-05 16:49:18

标签: c# linux

我有winform c#visual studio和一个在linux上运行的服务器。 我想执行这个命令" netstat -an | grep:80 | wc -l"来自我的winform界面 但我没有输出,我也不知道问题出在哪里。

这是我试过的

using System.Diagnostics;
using System.Security;
ProcessStartInfo proc_start_info = new ProcessStartInfo();
proc_start_info.FileName = "bash";
proc_start_info.Arguments = "-c netstat -an | grep :80 |wc -l ";
// -c allows to wait the command to be execute and exit
proc_start_info.RedirectStandardOutput = true;
proc_start_info.UseShellExecute = false;
proc_start_info.CreateNoWindow = true;
Process proc = new Process();
proc.StartInfo = proc_start_info;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
details_socket.Text = result;

0 个答案:

没有答案
相关问题