Azure App Service, run a native EXE to convert a file

醉酒当歌 提交于 2019-12-25 09:39:11

问题


I have a native EXE that converts a file based on command line arguments. Provided, I know how to give full path names of the input and output files, can I run such an EXE from my app service when some button is pressed and wait till the output file is created? Converting to DLL is not an option.


回答1:


As far as I know, we could run a native exe in the azure app service.

But we couldn't directly pass the parameter to the native exe.

You need write a web application or something else for the user to type in the input parameter.

Then you could use Process.Start method to run the exe.

About how to do it , you could refer to this code sample.

I use ASP.NET MVC to get the input parameter then send the parameter to the exe and get the result.

    public  ActionResult Index()
    {


        var proc = new Process
        {
            StartInfo = new ProcessStartInfo
            {
                FileName = Server.MapPath("/exe/Sum.exe"),
                //Arguments could be replaced 
                Arguments = "1 2",
                UseShellExecute = false,
                RedirectStandardOutput = true,
                CreateNoWindow = true
            }
        };

        proc.Start();
        while (!proc.StandardOutput.EndOfStream)
        {
            string line = proc.StandardOutput.ReadLine();
            // do something with line

            Response.Write( " The result is : " + line);

        }

        //await getResultAsync();
        return View();
    }

Result:



来源:https://stackoverflow.com/questions/46337633/azure-app-service-run-a-native-exe-to-convert-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!