zoukankan      html  css  js  c++  java
  • c# 调用外部程序的例子

     

    #region 一个调用外部程序的例子
      private static string CmdPing(string strIp)
      {
       Process p = new Process();
       p.StartInfo.FileName = "cmd.exe";
       p.StartInfo.UseShellExecute = false;
       p.StartInfo.RedirectStandardInput = true;
       p.StartInfo.RedirectStandardOutput = true;
       p.StartInfo.RedirectStandardError = true;
       p.StartInfo.CreateNoWindow = true;
       string pingrst;
       p.Start();
       p.StandardInput.WriteLine("telnet 192.168.3.175 9944");
       p.StandardInput.WriteLine("quit");
       p.StandardInput.WriteLine("exit");
       string strRst = p.StandardOutput.ReadToEnd();
       Trace.WriteLine(strRst);
       p.Close();
       return pingrst;
       }
    #endregion

    习惯改为;private static string Cmd(string strcmd)
    {
     Process p = new Process();
     p.StartInfo.FileName = "cmd.exe /c"+strcmd;
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.RedirectStandardInput = true;
     p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.RedirectStandardError = true;
     p.StartInfo.CreateNoWindow = true;
     p.Start();www.shengfang.org
     string strRst = p.StandardOutput.ReadToEnd();
     System.Diagnostics.Trace.WriteLine(strRst);
     p.Close();
     return strRst;
    }

  • 相关阅读:
    windows10远程桌面慢的解决
    linux挂载windows共享盘
    ORACLE 临时表空间满了的原因解决方案
    oracle临时表空间扩容
    expdp/impdp 数据泵导入导出
    Oracle Awr报告_生成
    mysql备份与保存
    oracle lsnrctl监听器多实例配置
    RabbitMQ
    docker stop 容器时 不能将我指定的容器停掉
  • 原文地址:https://www.cnblogs.com/asyuras/p/278405.html
Copyright © 2011-2022 走看看