zoukankan      html  css  js  c++  java
  • C# CMD吊起执行 传参式执行类

     1  class command
     2     {
     3         public static string startcmd(string command)
     4         {
     5             string output = "";
     6             try
     7             {
     8 
     9                 Process cmd = new Process();
    10                 cmd.StartInfo.FileName = command;
    11 
    12                 cmd.StartInfo.UseShellExecute = false;
    13 
    14                 cmd.StartInfo.RedirectStandardInput = true;
    15                 cmd.StartInfo.RedirectStandardOutput = true;
    16 
    17                 cmd.StartInfo.CreateNoWindow = true;
    18                 cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    19 
    20                 cmd.Start();
    21 
    22                 output = cmd.StandardOutput.ReadToEnd();
    23                 Console.WriteLine(output);
    24                 cmd.WaitForExit();
    25                 cmd.Close();
    26             }
    27             catch (Exception e)
    28             {
    29                 Console.WriteLine(e);
    30             }
    31             return output;
    32         }
    33         public static Process startcmd(string command, string argument)
    34         {
    35             string output = "";
    36             Process cmd = new Process();
    37             try
    38             {
    39                 cmd.StartInfo.FileName = command;
    40                 cmd.StartInfo.Arguments = argument;
    41 
    42                 cmd.StartInfo.UseShellExecute = false;
    43 
    44                 cmd.StartInfo.RedirectStandardInput = true;
    45                 cmd.StartInfo.RedirectStandardOutput = true;
    46 
    47                 cmd.StartInfo.CreateNoWindow = true;
    48                 cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    49 
    50                 cmd.Start();
    51 
    52                 //output = cmd.StandardOutput.ReadToEnd();
    53                 //Console.WriteLine(output);
    54                 //cmd.WaitForExit();
    55                 //cmd.Close();
    56             }
    57             catch (Exception e)
    58             {
    59                 Console.WriteLine(e);
    60             }
    61             return cmd;
    62         }
    63     }
    View Code
  • 相关阅读:
    go引入包一直是红色,没有引入的解决办法
    php 把抛出错误记录到日志中
    亚马逊查询接口
    git 合并指定文件到另一个分支
    content-type
    Echarts(饼图Pie)
    DIN 模型速记
    DeepFM 要点速记
    youtube DNN 模型要点速记
    java设计模式之迭代器
  • 原文地址:https://www.cnblogs.com/lewisli/p/4128919.html
Copyright © 2011-2022 走看看