C# 执行CMD返回信息
using System.Diagnostics;
/// <summary>
/// 执行CMD命令返回信息
/// </summary>
/// <param name="Command">命令</param>
/// <returns>返回命令执行结果</returns>
public string executeCmd(string Command)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe ";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(Command);
p.StandardInput.WriteLine("exit");
System.Threading.Thread.Sleep(1000);
string Re= p.StandardOutput.ReadToEnd();
p.StandardOutput.Close();
p.WaitForExit();
p.Close();
return Re;
}声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇: C# 数据类型和字节长度
