• c# 执行cmd 操作类


    public class CommandHelper
    {
    /// <summary>
    /// 执行系统CMD命令
    /// </summary>
    /// <param name="commandText">命令文本</param>
    /// <returns></returns>
    public static string ExecCommand(string commandText)
    {
    System.Diagnostics.Process process = new System.Diagnostics.Process();//启动Process进程管理对象
    process.StartInfo.FileName = "cmd.exe";//调用cmd shell
    process.StartInfo.UseShellExecute = false;//设置是否启用操作系统的Shell启动进程
    process.StartInfo.RedirectStandardInput = true;//应用程序的输入是否从RedirectStandardInput流中获取
    process.StartInfo.RedirectStandardOutput = true;//应用程序的输出是否写到RedirectStandardOutput流中
    process.StartInfo.RedirectStandardError = true;//是否将错误信息写入到RedirectStandardError流中
    process.StartInfo.CreateNoWindow = true;//是否在新窗口中启动该进程
    //p.StartInfo.WorkingDirectory = Server.MapPath("../resources/") + sessionPath;
    string strOutput = null;
    try
    {
    process.Start();
    process.StandardInput.WriteLine(commandText);
    process.StandardInput.WriteLine("exit");
    strOutput = process.StandardOutput.ReadToEnd();
    process.WaitForExit();
    process.Close();
    }
    catch (Exception e)
    {
    strOutput = e.Message;
    LogHelper.WriteMessageErrorLog(e.Message);
    }
    return strOutput;
    }
    }

  • 相关阅读:
    B树
    23查找树和红黑树
    红黑树---满足红黑性质的二叉查找树
    AVL树---平衡的二叉查找树
    二叉查找树
    Ping程序
    ICMP:Internet控制报文协议
    Unix&Linux大学教程目录
    Linux文件系统
    git简介
  • 原文地址:https://www.cnblogs.com/2260827114com/p/6479866.html
Copyright © 2020-2023  润新知