在 Azure 网站中启动 Process.Start [英] Process.Start in Azure Website
问题描述
我有一个 ASP.NET MVC 5 应用程序,我需要在我的 Azure 网站中使用 Process.Start
调用 wkhtml2pdf.exe.本地一切正常.但似乎我的应用程序停留在 Process.Start
行.Azure 是否支持启动进程?
I have an ASP.NET MVC 5 app where I need to invoke wkhtml2pdf.exe in my Azure website using Process.Start
. Locally everthing works fine. But it seems my app stuck at Process.Start
line. Is starting a process is supported on Azure?
推荐答案
ramiramilu 的回答其实并不正确.你可以运行任何你想要的 exe(检查这个例如).您遇到的问题不在于运行 exe,而是 wkhtml2pdf.exe
本身特有的问题.该 exe 在 Windows 上使用一堆 GDI+
调用来呈现 PDF,而这在 Azure 网站沙箱中是不允许的(GDI+
调用,而不是运行 exe).
ramiramilu's answer is actually not correct. You can run any exe you want (check this for example). The problem you are hitting is not in running an exe, it's something specific to wkhtml2pdf.exe
itself. That exe uses a bunch of GDI+
calls on Windows for rendering the PDF and that is what's not allowed in Azure Websites sandbox (the GDI+
calls, not running an exe).
使用 WebJob 也无济于事,因为 WebJob 运行在与站点相同的上下文中,这意味着在同一个沙箱下.
Using a WebJob won't help either because WebJobs run in the same context as the site which means under the same sandbox.
在 Azure 网站上启动外部进程的方式与通常使用 C# 的方式相比没有什么特别之处.您再次面临的问题是 wkhtml2pdf.exe
而不是启动进程的一般概念.
There is nothing special to how you would launch an external process on Azure Websites than how you would do it normally with C#. Again the problem you are facing is with wkhtml2pdf.exe
and not with the general concept of launching a process.
这是一个示例,您可以尝试启动 cmd.exe
并读取写入标准输出的内容
Here is a sample that you can try that launches cmd.exe
and reads what is written on stdout
var processStartInfo = new ProcessStartInfo()
{
Arguments = "/c echo "test"",
FileName = @"c:windowssystem32cmd.exe",
RedirectStandardOutput = true,
UseShellExecute = false
};
var process = Process.Start(processStartInfo);
using (var streamReader = new StreamReader(process.StandardOutput.BaseStream))
{
ViewBag.MessageFromExe = streamReader.ReadToEnd();
}
ViewBag.MessageFromExe
将具有 "test"
值,您可以在视图上验证它,并且可以在 Azure 网站中正常运行
ViewBag.MessageFromExe
will have the value "test"
you can verify that on your view and you can run that just fine in Azure Websites
这篇关于在 Azure 网站中启动 Process.Start的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!