C#中使用命令行命令
作者:互联网
本文演示了如何在C#中使用命令行代码:
string command = System.Configuration.ConfigurationSettings.AppSettings["Command"];//ping www.baidu.com
try
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + command;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
outputMsg = p.StandardOutput.ReadToEnd();
p.Close();
if (outputMsg.Contains("Reply"))
{
isComputerOn = "SUCCESS";
return true;
}
else
{
isComputerOn = "ERROR";
return false;
}
}
catch (Exception ex)
{
return false;
}
}
标签:isComputerOn,false,C#,return,命令,命令行,StartInfo,true 来源: https://blog.51cto.com/u_9894631/2789282