zoukankan      html  css  js  c++  java
  • [置顶] c#程序中如何执行 dos命令

     C#中执行Dos命令 C# 本来封装了很多 类似于Dos命令的东西,可是开发需要用它来执行 cmd.texe。

     static void Main(string[] args)
            {
                command.startcmd("ping");
                command.cmdPross("ping", "127.0.0.1");
            }


     public static string cmdPross(string command, string argument)
            {
                string output = "";
                try
                {
                    Process cmd = new Process();


                    cmd.StartInfo.FileName = command;
                    cmd.StartInfo.Arguments = argument;


                    cmd.StartInfo.UseShellExecute = false;


                    cmd.StartInfo.RedirectStandardInput = true;
                    cmd.StartInfo.RedirectStandardOutput = true;


                    cmd.StartInfo.CreateNoWindow = true;
                    cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;


                    cmd.Start();


                    output = cmd.StandardOutput.ReadToEnd();
                    Console.WriteLine(output);
                    cmd.WaitForExit();
                    cmd.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                return output;
            }

    遇见了就不要错过
  • 相关阅读:
    python Windows环境下文件路径问题
    pycharm 取消连按两下shift出现的全局搜索
    python2 与 python3的区别
    Python安装PyOpenGL
    Protobuffer学习文档
    python bin文件处理
    python 项目自动生成requirements.txt文件
    pytest文档7-pytest-html生成html报告
    python from __future__ import division
    细说 Java 的深拷贝和浅拷贝
  • 原文地址:https://www.cnblogs.com/Traner/p/2819937.html
Copyright © 2011-2022 走看看