13987

How to run a .EXE in an Azure App Service

Question:

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 };

Answer1:

<blockquote>

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

</blockquote>

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();

<a href="https://i.stack.imgur.com/QDuX0.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/QDuX0.png" data-original="https://i.stack.imgur.com/QDuX0.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a> <a href="https://i.stack.imgur.com/mTiO6.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/mTiO6.png" data-original="https://i.stack.imgur.com/mTiO6.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Recommend

  • Can I write tests for invalid lifetimes?
  • Should bit-fields less than int in size be the subject of integral promotion?
  • What is the purpose of webkitRelativePath property in File object?
  • How to access in PHP data returned in cursor from postgres function
  • how to make datetime class to work with DST and without DST in php?
  • flutter navigation to new screen not working
  • How to properly create a RollingFileAppender with AppenderComponentBuilder in log4j 2
  • Plotting a continuous stream of data with MatPlotLib
  • Scala and SBT install on Debian with Java 8
  • how to make all possible power set(or subset) from arrayList objects?
  • Setup SignalR and Service Bus inside a Azure Service Fabric service
  • SQLITE multiple table join with a condition
  • Connect from a client to a sails based server
  • How to use mixed C++ & .Net dll in node.js? (Error: abort() has been called)
  • Send HTML Mail with Unicode
  • Ways of filling 10 places with number from [1..10] such that digit at ith place has value atmost 1 m
  • Filtering out choiceless polls in the Django tutorial causes polls in the index to duplicate
  • How do you run a synchronous timer in C#?
  • How to move to lines with the same indentation in Visual Studio Code
  • Allowing audio files in Spring MVC 3.0?
  • Javascript inside HTML import not affecting imported HTML
  • C# code can't “see” the methods in my C++ dll
  • Does hibernate load two seprate copies of same instance if they are loaded twice from database?
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • Magento-Change Attribute of All Products
  • How to write seo friendly url's using htaccess?
  • Create an average of multiple excel chart without the data source
  • Django, uWSGI & nginx: Process dies for “no reason”
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • Comparing variables with strings bash
  • Print Longitude and Latitude in textbox Android
  • read part of h5 dataset python
  • Spring Boot fails to start
  • Using Service Component Runtime
  • Jersey serializes character value to ASCII equivalent numeric string
  • convert json to excel in java