zoukankan      html  css  js  c++  java
  • c#程序执行cmd命令

      private void ExecuteCMD(string cmd)
            {
             
                Process process = new Process();

                try
                {
                    process.StartInfo.FileName = "cmd.exe";
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.RedirectStandardInput = true;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError = true;
                   // process.StartInfo.CreateNoWindow = true;

                    process.Start();
                    process.StandardInput.WriteLine(cmd);
                    process.StandardInput.WriteLine("exit");
                    process.WaitForExit();

                    string readProOutResult = process.StandardOutput.ReadToEnd();

                }
                catch (Exception ex)
                {
                    MessageBox.Show("操作失败");
                }
                finally
                {
                    process.Close();
                }

  • 相关阅读:
    【linux】驱动-13-阻塞与非阻塞
    【linux】驱动-12-并发与竞态
    【linux】驱动-11-gpio子系统
    【linux】驱动-10-pinctrl子系统
    【linux】驱动-9-设备树插件
    手写Java分页模块
    JDBC连接与自定义线程池
    类加载器
    网络编程之TCP
    网络编程之UDP
  • 原文地址:https://www.cnblogs.com/chenleinet/p/2110601.html
Copyright © 2011-2022 走看看