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

查看:19
本文介绍了如何在 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.

我已将 .exe 添加到我在 Visual Studio 中项目的顶层,并添加了一个文件夹,其中包含 .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.

我正在努力研究如何获取 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
};

推荐答案

我正在努力研究如何获取 exes 和文件文件夹的路径.

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

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

If your files under the top-level of project. We can find the path by using Server.MapPath(@"~JarTextFile1.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(@"~JarTextFile1.txt");    //get file path on the top-level of project(eg. ~folderxxx)
        string JavaPath = Environment.GetEnvironmentVariable("JAVA_HOME", EnvironmentVariableTarget.Machine); 
        if(string.IsNullOrEmpty(JavaPath)){
         JavaPath = Environment.GetEnvironmentVariable("JAVA_HOME", EnvironmentVariableTarget.User);
        }
        string path = JavaPath + @"injarsigner.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天全站免登陆