0

i have winform c# visual studio and a server running in linux. i want to execute this command " netstat -an | grep :80 |wc -l " from my winform interface but i have no output and i don't know where is the problem.

this is what i have tried

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;
Robert Columbia
  • 6,313
  • 15
  • 32
  • 40
djient
  • 21
  • 1
  • 6
  • try proc.WaitForExit() before you call read to end – Steve Aug 05 '16 at 16:53
  • You have VS on Linux? Please confirm that your WinForm executable runs on the same machine you need to run "netstat" – Alexei Levenkov Aug 05 '16 at 16:54
  • I think [this](http://stackoverflow.com/questions/6147203/automating-running-command-on-linux-from-windows-using-putty) will get you going in the right direction. You need an SSH client or Putty in order to execute linux commands remotely from you windows. – Gilad Green Aug 05 '16 at 17:00
  • Is this running on a client or the server itself using Mono? – EJoshuaS - Stand with Ukraine Aug 05 '16 at 17:22
  • my VS turns on windows not linux – djient Aug 05 '16 at 18:55
  • guys now an error appears at: proc.Start(); the error is:"The specified file can not be found" Do you think the probleme is proc_start_info.FileName = "bash"; so what to do? – djient Aug 05 '16 at 19:12
  • let me set the question in another manner: how can i from my winform access the remote linux server by opening putty and passing a command for its execution – djient Aug 08 '16 at 08:27

0 Answers0