简体   繁体   English

在C#流程中添加用户输入

[英]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. 因此,我试图让一个ip pinger来查看服务器是否在线,并且到目前为止,我希望它能够使用户可以从文本框中自己放置一个ip。 but keep getting a error on the start part. 但是在开始部分总是出错。

Error CS1501 No overload for method 'Start' takes 3 arguments 错误CS1501方法“启动”没有重载,需要3个参数

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. 首先,由于前面使用逗号,因此将"-t"用作第三个参数。 You should add it to the string you're building with "/k" in combination with the IP address. 您应该将其添加到使用"/k"与IP地址结合使用的字符串中。

Next, given the textbox text is "127.0.0.1" this will currently end up as: /k ping127.0.0.1 接下来,给定文本框文本为"127.0.0.1"当前该文本将最终显示为: /k ping127.0.0.1

So you might just add a space in between the "ping" and the IP. 因此,您可以在“ ping”和IP之间添加一个空格。

BUT: you should not use cmd.exe for this, consider to use the Ping class from the .NET framework. 但是:您不应为此使用cmd.exe,请考虑使用.NET框架中的Ping类

Try using ProcessStartInfo: 尝试使用ProcessStartInfo:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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