在Azure Function中运行.exe可执行文件 [英] Run .exe executable file in Azure Function

查看:135
本文介绍了在Azure Function中运行.exe可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可执行文件abcd.exe(包含/合并了许多.dll). 是否可以为abcd.exe创建Azure Function并在Azure Cloud Functions中运行它?

I have executable abcd.exe (it contains/merged with many .dll). Is it possible to create Azure Function for abcd.exe and run it in Azure Cloud Functions?

abcd.exe应用程序:

The abcd.exe application :

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

abcd.exe应用程序没有UI(GUI),但它是数学和科学应用程序,它依赖于abcd.exe中合并的许多.dll.

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创建Azure功能并在Azure云功能中运行它?

Is it possible to create Azure Function for abcd.exe and run it in Azure Cloud Functions?

是的,我们可以上载.exe文件并在Azure Function应用中运行它.我创建了一个TimerTrigger Function应用程序,然后运行一个.exe,它将记录插入到此Function应用程序中的数据库中,对我而言效果很好.

Yes, we can upload .exe file and run it in Azure Function app. 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.

function.json

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

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

将.exe文件上传到Function应用程序文件夹

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

查询数据库,我可以从我的.exe文件中找到测试记录.

这篇关于在Azure Function中运行.exe可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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