我正在使用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));