C# 调用cmd执行命令

mac2022-06-30  75

private void CmdRun_Click(object sender, EventArgs e)        {            Process p = new Process();  // 初始化新的进程            p.StartInfo.FileName = "CMD.EXE"; //创建CMD.EXE 进程            p.StartInfo.RedirectStandardInput = true; //重定向输入            p.StartInfo.RedirectStandardOutput = true;//重定向输出            p.StartInfo.UseShellExecute = false; // 不调用系统的Shell            p.StartInfo.RedirectStandardError = true; // 重定向Error            p.StartInfo.CreateNoWindow = true; //不创建窗口            p.Start(); // 启动进程            p.StandardInput.WriteLine("dir c:\\"); // Cmd 命令            p.StandardInput.WriteLine("exit"); // 退出            string s = p.StandardOutput.ReadToEnd(); //将输出赋值给 S            p.WaitForExit();  // 等待退出                              }

转载于:https://www.cnblogs.com/ttssrs/p/4350297.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)