C#如何随机获取一个可用端口 如题,要获取一个端口号,而且这个端口号可用 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // <summary> /// 执行DOS命令,返回DOS命令的输出 /// </summary> /// <param name="dosCommand">dos命令</param> /// <param name="milliseconds">等待命令执行的时间(单位:毫秒),如果设定为0,则无限等待</param> /// <returns>返回输出,如果发生异常,返回空字符串</returns> public static string Execute(string dosCommand, int milliseconds) { string output = ""; //输出字符串 if (dosCommand != null && dosCommand != "") { Process process = new Process(); //创建进程对象 ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "cmd.exe"; //设定需要执行的命令 startInfo.Arguments = "/C " + dosCommand; //设定参数,其中的“/C”表示执行完命令后马上退出 startInfo.UseShellExecute = false; //不使用系统外壳程序启动 startInfo.RedirectStandardInput = false; //不重定向输入 startInfo.RedirectStandardOutput = true; //重定向输出 startInfo.CreateNoWindow = true; //不创建窗口 process.StartInfo = startInfo; try { if (process.Start()) //开始进程 { if (milliseconds == 0) process.WaitForExit(); //这里无限等待进程结束 else process.WaitForExit(milliseconds); //这里等待进程结束,等待时间为指定的毫秒 output = process.StandardOutput.ReadToEnd();//读取进程的输出 } } catch { } finally { if (process != null) process.Close(); } } return output; } winform 新浪微博API获取自已的关注列表 access_token无法获取 请教一个验证码识别方法(rgb颜色格式和hsl格式的互换) Webbrowser的Navigate问题 IE7 使用socket异步接收数据的问题? C/S程序,客户端访问服务器的电子文件附件 sql stored procedure 问题,请大家帮忙 *.NET平台有C#,想加装支持VB(VB.NET) 怎么办? * CLC 脚本语言之留言版示例 C#控制Word打开文档后,如何设置文档不可编辑? 求救,水晶报表突然不能预览和打印! 高分求救串口打不开啦 C#程序如何设计才能不被Reflector等反编译
// <summary>
/// 执行DOS命令,返回DOS命令的输出
/// </summary>
/// <param name="dosCommand">dos命令</param>
/// <param name="milliseconds">等待命令执行的时间(单位:毫秒),如果设定为0,则无限等待</param>
/// <returns>返回输出,如果发生异常,返回空字符串</returns>
public static string Execute(string dosCommand, int milliseconds)
{
string output = ""; //输出字符串
if (dosCommand != null && dosCommand != "")
{
Process process = new Process(); //创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe"; //设定需要执行的命令
startInfo.Arguments = "/C " + dosCommand; //设定参数,其中的“/C”表示执行完命令后马上退出
startInfo.UseShellExecute = false; //不使用系统外壳程序启动
startInfo.RedirectStandardInput = false; //不重定向输入
startInfo.RedirectStandardOutput = true; //重定向输出
startInfo.CreateNoWindow = true; //不创建窗口
process.StartInfo = startInfo;
try
{
if (process.Start()) //开始进程
{
if (milliseconds == 0)
process.WaitForExit(); //这里无限等待进程结束
else
process.WaitForExit(milliseconds); //这里等待进程结束,等待时间为指定的毫秒
output = process.StandardOutput.ReadToEnd();//读取进程的输出
}
}
catch
{
}
finally
{
if (process != null)
process.Close();
}
}
return output;
}