0

I am trying to pass a string of arguments that will open a command line, and pass the specified arguments upon a button click. I am trying to define one value as the contents of a text box (constant ping to the IP address listed in the box). It will open the command line but will not pass any arguments, can anyone assist?

private void Pingbutt_Click(object sender, EventArgs e)
    {
        System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
        proc.FileName = @"C:\windows\system32\cmd.exe";
        String s = Cmiptxt.Text;
        proc.Arguments = (@"c/ ping" + s + "-t");
        System.Diagnostics.Process.Start(proc);
    }

2 Answers 2

2

Looks like you're missing a space before and after your ip, string.Format would make this easier the read

proc.Arguments = string.Format("c/ ping {0} -t", s);

Alternatively, a simple way to implement this would be to use the Process.Start(string, string) overload

Process.Start("cmd.exe", string.Format("c/ ping {0} -t", s));
Sign up to request clarification or add additional context in comments.

2 Comments

even using the string.Format it is acting the same, opens the command prompt but it is not entering "ping" the ip or -t. I am unfamiliar with the Process.Start(string, string) overload...
I figured it out, I neglected to remove the second process start argument and it was attempting to start 2 separate processes...
0

I try this one. not working corectly. cmd open. not runing command.

 private void btnDownload_Click(object sender, EventArgs e)
    {

       Process.Start("cmd.exe", string.Format("ipconfig"));
    }

Comments

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.