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;
7
  • try proc.WaitForExit() before you call read to end Commented Aug 5, 2016 at 16:53
  • You have VS on Linux? Please confirm that your WinForm executable runs on the same machine you need to run "netstat" Commented Aug 5, 2016 at 16:54
  • I think this 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. Commented Aug 5, 2016 at 17:00
  • Is this running on a client or the server itself using Mono? Commented Aug 5, 2016 at 17:22
  • my VS turns on windows not linux Commented Aug 5, 2016 at 18:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.