zoukankan      html  css  js  c++  java
  • C#调用DOS程序

    需要添加引用System.Diagnostic

    Process process = new Process();  //创建进程对象
    process.StartInfo.FileName = "cmd.exe";  //要执行的程序名
    
    process.StartInfo.UseShellExecute = false;  ////不使用系统外壳程序启动进程
    process.StartInfo.CreateNoWindow = true;  //不显示dos程序窗口
    
    //重新定向标准输入,输入,错误输出
    process.StartInfo.RedirectStandardInput = true;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;
    
    process.Start();  //进程开始
    
    //输入dos命令
    process.StandardInput.WriteLine("cd C:\\mysql\\bin");
    process.StandardInput.WriteLine("net stop mysql");
    process.StandardInput.WriteLine("mysqld -remove");
    process.StandardInput.WriteLine("exit");
    
    string strRst = process.StandardOutput.ReadToEnd(); //获取结果 
    
    process.WaitForExit();  //等待命令结束
    process.Close();  //进程结束

    如果仅是调用dos程序并输入参数是,也可以这样

    ProcessObj.StartInfo.FileName = @"C:\User\example.exe";  //调用程序名
    ProcessObj.StartInfo.Arguments = "-c -x";  //输入参数
  • 相关阅读:
    js参数自定义
    分页插件--记录
    .net mvc接收参数为null的解决方案
    c#枚举转字典或表格
    openlayers添加弹出框
    openlayers按坐标点播放
    openlayers轨迹匀速播放
    MyEclipse配置进行Hibernate逆映射
    BIO,NIO,AIO
    Git遇到的一点错误
  • 原文地址:https://www.cnblogs.com/xpvincent/p/2844118.html
Copyright © 2011-2022 走看看