【问题标题】:Web Application Asp.Net: Execute a Dos CommandWeb 应用程序 Asp.Net:执行 Dos 命令
【发布时间】:2011-10-25 01:21:18
【问题描述】:

我有一个 Web 应用程序,我想将命令发送到命令行(命令未知)。这是我使用的方法

    public static string ExecuteCommand(string command)
    {
        String result;
        try
        {
            //Create a new ProcessStartInfo
            System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
            //Settings
            procStartInfo.UseShellExecute = false;
            procStartInfo.CreateNoWindow = true;
            //Create new Process
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            //Set ProcessStartInfo
            proc.StartInfo = procStartInfo;
            //Start Process
            proc.Start();
            //Wait to exit
            proc.WaitForExit();
            //Get Result
            result = proc.StandardOutput.ReadToEnd();
            //Return
            return result;
        }
        catch
        {
        }
        return null;
    }

该命令适用于控制台应用程序,但不适用于 Web 应用程序(返回 null)

    public string test = "NOTHING";

    protected void Page_Load(object sender, EventArgs e)
    {
        test = AppCommandHandler.ExecuteCommand("mkdir test2");
    }

我做错了什么?我看的每个教程都告诉我使用ProcessStartInfo

编辑我不断收到此错误:

{"StandardOut 未重定向或进程未启动 还没有。”}

【问题讨论】:

    标签: c# asp.net web-applications command


    【解决方案1】:

    网络应用的池是否有足够的权限来执行这个命令?

    【讨论】:

    • 让我看看如何检查,我会回复你
    • 检查您网站的应用程序池在 IIS 下运行的帐户。我猜只有“本地进程”才能执行命令行的东西(?)。
    • 是的,这就是问题所在。感谢您的帮助!
    【解决方案2】:

    你不能这样做,但你必须直接使用 java 来做到这一点,只需查看链接:

    Run a cmd command with asp dotnet app

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 2011-10-12
      • 1970-01-01
      相关资源
      最近更新 更多