Question

I created a windows form application that runs a ping command when a button is pressed. I previously asked the question "Is there any way that I could copy the output from the CMD window to the clipboard?" without realizing that when the process is executed no command is run. It just opens CMD.

This is what I am using to run the CMD process:

Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
//startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = pingData;
process.StartInfo = startInfo;
process.Start();

Here is the code behind "pingData", what I am using for my argument:

pingData = "ping s0" + textBox1.Text + "r100";

textBox1 only has up to 4 numbers at a given time.

Thank you!

Was it helpful?

Solution

You need to add /C to your arguments list and then the command name and its arguments. /C Carries out the command specified by string and then terminates

Do note: this question has been asked & answered already: Issue executing a command with cmd.exe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top