Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a .EXE in an Azure App Service

I have an MVC .NET application, and I want to run some .exes on the server. The exes are jarsigner.exe and zipalign.exe, used to modify and re-sign an android APK. I want to run them from the Controller.

It works locally, using a Process to launch the application, but I have cheated and used hardcoded paths to the .exe and to the folder with the stuff to be used by the exe.

I've added the .exes to the top-level of my project in visual studio, and added a folder containing the files to be worked upon by the .exes.

I'm struggling to workout how I get the path to the exes, and to the folder of files. Once I have that I can then invoke the Process (I suspect I might hit permissions trouble, but one step at a time...).

var processInfo = new ProcessStartInfo(@"C:\jarsigner.exe", @"..arguments"){
 CreateNoWindow = true, UseShellExecute = false
};
like image 846
gregm Avatar asked Apr 05 '17 14:04

gregm


People also ask

Can I run exe on Azure?

Go to ProjectA, Right Click, then Go to Properties, then in the Application Panel, Select Output type as Console Application. This is a MUST ! Then Build. You can Copy the bin Folder, where the Application's exe is, and paste to a folder inside the Azure Function App.

How do I run an exe file app?

After you download your desired exe on your Android phone, download and install Inno Setup Extractor from the Google Play Store, use a file browser to locate the exe file, and open that file with the app. Inno Setup Extractor will then extract the exe on your Android phone, and you can check out those files afterward.

How do I run an exe file from the cloud?

The easiest way to run a .exe file on one Windows computer from another is with the PsExec command. With appropriate permissions and other security settings, you could run a .exe on a computer in the cloud from your own computer or on your computer from one in the cloud.

What can run on Azure App Service?

Multiple languages and frameworks - App Service has first-class support for ASP.NET, ASP.NET Core, Java, Ruby, Node. js, PHP, or Python. You can also run PowerShell and other scripts or executables as background services.


1 Answers

I'm struggling to workout how I get the path to the exes, and to the folder of files.

If your files under the top-level of project. We can find the path by using Server.MapPath(@"~\Jar\TextFile1.txt"). For jarsigner.exe. It’s in the bin folder of your java JDK. So we can use the environment variable.

Here is the sample code to get the path of jarsigner.exe and running result.

//string path = Server.MapPath(@"~\Jar\TextFile1.txt");    //get file path on the top-level of project(eg. ~\folder\xxx)
        string JavaPath = Environment.GetEnvironmentVariable("JAVA_HOME", EnvironmentVariableTarget.Machine); 
        if(string.IsNullOrEmpty(JavaPath)){
         JavaPath = Environment.GetEnvironmentVariable("JAVA_HOME", EnvironmentVariableTarget.User);
        }
        string path = JavaPath + @"\bin\jarsigner.exe";

        var processInfo = new ProcessStartInfo()
        {
            FileName = path,
            CreateNoWindow = true,
            UseShellExecute = false,
            WindowStyle = ProcessWindowStyle.Hidden
        };

        Process proc = Process.Start(processInfo);
        proc.WaitForExit();
        if (proc.ExitCode == 0)
            ViewBag.Message = path + " exec success.";
        else
            ViewBag.Message = path + " exec fail.";

        return View();

enter image description here enter image description here

like image 184
Terry Fei Avatar answered Sep 30 '22 07:09

Terry Fei