例如:
string c = @"net start ServiceDemo";
            Cmd(c);
 string c = @"c:\windows\microsoft.net\framework\v2.0.50727\InstallUtil.exe " + AppDomain.CurrentDomain.BaseDirectory + "ServiceDemo.exe";
            Cmd(c);
 
 /// <summary>
        /// 执行Cmd命令
        /// </summary>
        public void Cmd(string c)
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo.FileName = "cmd.exe";
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardInput = true;
            process.Start();

            process.StandardInput.WriteLine(c);
            process.StandardInput.AutoFlush = true;
            process.StandardInput.WriteLine("exit");

            StreamReader reader = process.StandardOutput;//截取输出流

            string output = reader.ReadLine();//每次读取一行

            while (!reader.EndOfStream)
            {
                PrintThrendInfo(output);
                output = reader.ReadLine();
            }

            process.WaitForExit();
        }

相关文章:

  • 2021-11-12
  • 2022-01-28
  • 2022-12-23
  • 2021-11-18
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
猜你喜欢
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-09-06
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案