简体   繁体   English

在Azure功能中运行.exe可执行文件

[英]Run .exe executable file in Azure Function

I have executable abcd.exe (it contains/merged with many .dll). 我有可执行文件abcd.exe(它包含/合并了许多.dll)。 Is it possible to create Azure Function for abcd.exe and run it in Azure Cloud Functions? 是否可以为abcd.exe创建Azure功能并在Azure云功能中运行它?

The abcd.exe application : abcd.exe应用程序:

System.Diagnostics.Process process = new System.Diagnostics.Process();

System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

startInfo.FileName = "cmd.exe";

**startInfo.Arguments = "/C abcd.exe";**

process.StartInfo = startInfo;

process.Start();

The abcd.exe application does not have UI (GUI), but it is math and scientific Application and it depend from many .dll which are merged inside abcd.exe. abcd.exe应用程序没有UI(GUI),但它是数学和科学应用程序,它依赖于许多.dll,它们在abcd.exe中合并。

Thank you 谢谢

Is it possible to create Azure Function for abcd.exe and run it in Azure Cloud Functions? 是否可以为abcd.exe创建Azure功能并在Azure云功能中运行它?

Yes, we can upload .exe file and run it in Azure Function app. 是的,我们可以上传.exe文件并在Azure Function应用程序中运行它。 I create a TimerTrigger Function app, and run a .exe that insert record into database in this Function app, which works fine on my side. 我创建了一个TimerTrigger函数应用程序,并运行一个.exe,它将记录插入到这个函数应用程序的数据库中,这对我来说很好。

function.json function.json

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */1 * * * *"
    }
  ],
  "disabled": false
}

run.csx run.csx

using System;

public static void Run(TimerInfo myTimer, TraceWriter log)
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = @"D:\home\site\wwwroot\TimerTriggerCSharp1\testfunc.exe";
    process.StartInfo.Arguments = "";
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;
    process.Start();
    string output = process.StandardOutput.ReadToEnd();
    string err = process.StandardError.ReadToEnd();
    process.WaitForExit();

    log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}

Upload .exe file to Function app folder 将.exe文件上传到Function app文件夹

在此输入图像描述

Main code in my .exe program 我的.exe程序中的主要代码

SqlConnection cn = new SqlConnection("Server=tcp:{dbserver}.database.windows.net,1433;Initial Catalog={dbname};Persist Security Info=False;User ID={user_id};Password={pwd};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;

cmd.CommandText = "insert into [dbo].[debug]([Name]) values('test')";

cmd.ExecuteNonQuery();
cn.Close();

Query the database, I can find the test record is inserted from my .exe file. 查询数据库,我可以找到从我的.exe文件中插入的测试记录。 在此输入图像描述

Fred Thank you very much for your help. 弗雷德非常感谢你的帮助。 Now, with minor modification the application is compiling and running. 现在,只需稍加修改即可编译并运行应用程序。

Some minor modifications to the application: 对应用程序的一些小修改:

using System;

using System.Diagnostics;

using System.Threading;


public static void Run(TimerInfo myTimer, TraceWriter log)
{

    System.Diagnostics.Process process = new System.Diagnostics.Process();
    string WorkingDirectoryInfo =@"D:\home\site\wwwroot\TimerTriggerCSharp1";
    string ExeLocation = @"D:\home\site\wwwroot\TimerTriggerCSharp1\MyApplication.exe";
    Process proc = new Process();
    ProcessStartInfo info = new ProcessStartInfo();

    try
    {
    info.WorkingDirectory = WorkingDirectoryInfo;
    info.FileName = ExeLocation;
    info.Arguments = "";
    info.WindowStyle = ProcessWindowStyle.Minimized;
    info.UseShellExecute = false;
    info.CreateNoWindow = true;
    proc.StartInfo = info;
    proc.Refresh();
    proc.Start();
    proc.WaitForInputIdle();
    proc.WaitForExit();
    }
    catch
    {
    }
    log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可执行文件可以作为Blob触发的Azure函数的一部分运行吗? - Can an executable be run as a part of a blob-triggered Azure Function? 如何使用输入参数在 azure 数据工厂中运行 exe 文件? - how to run exe file in azure data factroy with input parameters? Azure应用服务,运行本机EXE来转换文件 - Azure App Service, run a native EXE to convert a file 通过使用“包装器”或“ exe代理”在其他exe的上下文中运行可执行文件 - Run executable in context of a different exe by using a “wrapper” or “exe proxy” 使用 azure 自定义活动运行 c# 可执行文件,将 DBF 文件转换为 CSV - Using azure custom activity to run c# executable which converts DBF file into CSV 如何在AppDomain中运行可执行文件? - How to run executable file in AppDomain? Azure 函数通过从 azure blob 存储中获取文件作为输入参数来执行 exe - Azure function execute exe by getting file from azure blob storage as input params 使用Azure ADF V2运行.EXE - Run .EXE in using Azure ADF V2 从FileStream运行exe文件 - Run exe file from FileStream 我如何以编程方式向资源添加可执行文件(.exe)? - How i can add an executable file(.exe) to Resources programmatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM