简体   繁体   中英

adding a user input into c# process

So im trying to make a ip pinger to see if a server is online and have got this so far i would like it so that the user can in put a ip on there own from a text box. but keep getting a error on the start part.

Error CS1501 No overload for method 'Start' takes 3 arguments

System.Diagnostics.Process.Start ("cmd", "/k ping"  + flatTextBox1.Text ,"-t");

I see several issues here:

First, the "-t" is used as third parameter because of the comma before it. You should add it to the string you're building with "/k" in combination with the IP address.

Next, given the textbox text is "127.0.0.1" this will currently end up as: /k ping127.0.0.1

So you might just add a space in between the "ping" and the IP.

BUT: you should not use cmd.exe for this, consider to use the Ping class from the .NET framework.

Try using ProcessStartInfo:

ProcessStartInfo startInfo = new ProcessStartInfo("cmd");
startInfo.Arguments = "/k ping " + flatTextBox1.Text + " -t";
Process.Start(startInfo);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM