如何在 Azure 应用服务中运行 .EXE

How to run a .EXE in an Azure App Service(如何在 Azure 应用服务中运行 .EXE)
本文介绍了如何在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)