I have made an application in C# visual studio 2010. In this application I am sending ping
command to cmd
and the receiving the output of the cmd
in a RichTextBox
. Here is my code:-
void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
string newLine = e.Data.Trim() + Environment.NewLine;
MethodInvoker append = () => txtOutput.Text += newLine;
txtOutput.BeginInvoke(append);
}
}
private void btnPing_Click(object sender, EventArgs e)
{
string command = "/c ping " + txtPing.Text;
ProcessStartInfo procStartInfo = new ProcessStartInfo("CMD", command);
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
proc.Start();
proc.BeginOutputReadLine();
proc.WaitForExit();
}
my code is working great but the issue is cmd
is also getting popup when I click on start
button. And I want to hide this cmd
as I want to show output only in RichTextBox.
So, my question is, how can I hide cmd
in my application.
here is the screen shot of my problem.