user173399 user173399 - 26 days ago 10
C# Question

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

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.

Answer Source

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:

enter image description here