如何在Azure应用服务中运行.EXE [英] How to run a .EXE in an Azure App Service

查看:154
本文介绍了如何在Azure应用服务中运行.EXE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC .NET应用程序,并且我想在服务器上运行一些.exe. exe文件为jarsigner.exe和zipalign.exe,用于修改和重新签名android APK.我想从Controller中运行它们.

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.

它在本地运行,使用进程来启动应用程序,但是我欺骗并使用了指向.exe和指向该exe所用内容的文件夹的硬编码路径.

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.

我已经将.exes添加到了Visual Studio项目的顶层,并添加了一个文件夹,其中包含要由.exes处理的文件.

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.

我正在努力锻炼如何获取exe和文件文件夹的路径.一旦有了,我就可以调用该流程(我怀疑我可能遇到权限问题,但一次只能执行一个步骤...).

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

推荐答案

我正在努力锻炼如何获取exe和文件文件夹的路径.

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

如果您的文件位于项目的顶级之下.我们可以使用Server.MapPath(@〜\ Jar \ TextFile1.txt")找到该路径. 对于jarsigner.exe.它位于您的Java JDK的bin文件夹中.这样我们就可以使用环境变量了.

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.

这是获取jarsigner.exe路径和运行结果的示例代码.

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

这篇关于如何在Azure应用服务中运行.EXE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆