在Azure网站中启动Process.Start [英] Process.Start in Azure Website

查看:67
本文介绍了在Azure网站中启动Process.Start的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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并读取stdout上写的内容

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:\windows\system32\cmd.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆