C# 执行bat文件并取得回显

来源:互联网 发布:windows 端口查看命令 编辑:程序博客网 时间:2024/06/05 17:41
using System.IO;using System.Diagnostics;ProcessStartInfo pro = new System.Diagnostics.ProcessStartInfo("cmd.exe");pro.UseShellExecute = false;pro.RedirectStandardOutput = true;pro.RedirectStandardError = true;pro.CreateNoWindow = true;pro.Arguments = "/K " + System.Environment.CurrentDirectory + @"\net_create.bat";pro.WorkingDirectory = System.Environment.CurrentDirectory;System.Diagnostics.Process proc = System.Diagnostics.Process.Start(pro);System.IO.StreamReader sOut = proc.StandardOutput;proc.Close();string results = sOut.ReadToEnd().Trim(); //回显内容sOut.Close();

原创粉丝点击