.Net Core Blazor服务器端。在已部署的服务器上执行exe和bat文件

时间:2020-10-26 02:39:36

标签: c# .net .net-core blazor

我正在使用Blazor服务器端进行开发和分发,并且正在尝试在已部署的服务器上运行exe,bat文件。 当使用以下代码运行时,它在本地运行得很好,但是当部署到服务器时,它不会运行。 部署的服务器环境正在与IIS一起分发。

如果在服务器上运行文件还有其他设置,请告诉我。 或者,如果代码错误。我希望获得帮助。

=============== Function Definition ===============
public void ExecuteCommand(string command)
{
    int exitCode;
    ProcessStartInfo processInfo;
    Process process = new Process();
    processInfo = new ProcessStartInfo("cmd.exe", "/C " + command);
    processInfo.WorkingDirectory = Path.Combine(_environment.WebRootPath, "test");
    processInfo.CreateNoWindow = true;
    processInfo.UseShellExecute = false;
    processInfo.Verb = "runas";

    processInfo.RedirectStandardError = true;
    processInfo.RedirectStandardOutput = true;

    process = Process.Start(processInfo);
    process.WaitForExit();

    string output = process.StandardOutput.ReadToEnd();
    string error = process.StandardError.ReadToEnd();
    exitCode = process.ExitCode;
    Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
    Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
    Console.WriteLine("ExitCode: " + exitCode.ToString(), "ExecuteCommand");
    process.Close();
}

=============== Execute Function ===============

ExecuteCommand(string.Format("batchTest.bat {0}", userDirPath));

0 个答案:

没有答案