zoukankan      html  css  js  c++  java
  • C#调用windows命令行(CMD)

    using System.Diagnostics;

    public static void StartCmd(String command)
    {
    Process p = new Process();
    p.StartInfo.FileName = "cmd.exe"; //命令
    p.StartInfo.UseShellExecute = false; //不启用shell启动进程
    p.StartInfo.RedirectStandardInput = true; // 重定向输入
    p.StartInfo.RedirectStandardOutput = true; // 重定向标准输出
    p.StartInfo.RedirectStandardError = true; // 重定向错误输出
    p.StartInfo.CreateNoWindow = true; // 不创建新窗口
    p.Start();
    p.StandardInput.WriteLine(command); //cmd执行的语句
    //p.StandardOutput.ReadToEnd(); //读取命令执行信息
    p.StandardInput.WriteLine("exit"); //退出
    }

  • 相关阅读:
    super与this的比较
    队列学习小结
    最左原则
    show processlist
    循环
    打印偶数
    发布模块
    eval函数
    文件
    模块
  • 原文地址:https://www.cnblogs.com/cherious/p/6417414.html
Copyright © 2011-2022 走看看