Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

asp.net - Process.Start in Azure Website

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

Using a WebJob won't help either because WebJobs run in the same context as the site which means under the same sandbox.

Edit:

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.

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 will have the value "test" you can verify that on your view and you can run that just fine in Azure Websites


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...