Fanna1119
Fanna1119

Reputation: 2316

c# String textbox text in a command line

I'm very new to C# do bear with my horrible flaws. :P

So I want my button to ping a site using basic command lines but for some reason it doesn't want to print it on the command line.

        private void button1_Click(object sender, EventArgs e)
    {
        string URL = textBox1.Text;

        string strCmdText;
        strCmdText = "ping" + URL;
        System.Diagnostics.Process.Start("CMD.exe", strCmdText);
    }

The textBox1's text contains the sites url that in this case it was "www.google.com"

https://i.sstatic.net/2WMSz.jpg

I have seen many different methods to this but not one of them is near anything I want to do in this case.

thanks :)

Upvotes: 0

Views: 1523

Answers (2)

Abe Miessler
Abe Miessler

Reputation: 85116

You might also look at the Ping class if you don't want to use the command line.

Ping pingSender = new Ping();
PingReply reply = pingSender.Send(URL);

Upvotes: 5

I4V
I4V

Reputation: 35363

string strCmdText = "/c ping " + URL;

System.Diagnostics.Process.Start("CMD.exe",strCmdText);

Upvotes: 3

Related Questions