【问题标题】:Run .exe with DLLs in Azure Function在 Azure Function 中使用 DLL 运行 .exe
【发布时间】:2019-02-22 08:38:40
【问题描述】:

我想通过 Azure Functions 执行依赖于 DLL 的 C++ .exe。它适用于我的本地机器以及使用 kudo 控制台启动 exe 时。

就像Run .exe executable file in Azure Function 中的帖子一样,我建议我准备好 run.csx 并将 .exe 和 DLL 加载到同一文件夹“D:\home\site\wwwroot\QueueTriggerCSharp1\”中。

当不需要 C++ 代码中的 DLL 时,它可以工作。否则,C++ 找不到 DLL(与 .exe 位于同一文件夹中),退出代码为 -1073741701。 如果我不上传 DLL,我会得到相同的退出代码。

我应该在哪里加载 DLL,或者还有其他原因吗?

run.csx-代码:

using System;
using System.Threading;
using System.Diagnostics;

public static void Run(TimerInfo myTimer, TraceWriter log)
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    string WorkingDirectoryInfo =@"D:\home\site\wwwroot\QueueTriggerCSharp1\";
    string ExeLocation = @"D:\home\site\wwwroot\QueueTriggerCSharp1\WriteDatebase2.exe";
    Process proc = new Process();
    ProcessStartInfo info = new ProcessStartInfo();
    info.WorkingDirectory = WorkingDirectoryInfo;
    log.Info($"WorkingDirectory: {info.WorkingDirectory}");
    info.FileName = ExeLocation;
    info.Arguments = "";
    info.UseShellExecute = false;
    info.CreateNoWindow = true;
    proc.StartInfo = info;
    proc.Start();
    proc.WaitForExit();
    int exitcode=proc.ExitCode;
    log.Info($"ExitCode: {exitcode}");
}

当我使用 python azure 函数启动 exe 时,也会出现同样的错误。在 kudo 控制台中启动 python 脚本有效。

有人有类似的问题吗?

谁能帮帮我? 谢谢!

【问题讨论】:

  • 感谢您的回复!有用!它在 Kudo 控制台中有效而在 azure 函数中无效的原因可能是什么?
  • 我用与 azure 函数相同的方法(使用 DLL 调用 C++ exe)编写了一个控制台应用程序,并将生成的 exe 放在不同的位置。如果我用 Kudo 控制台执行控制台应用程序,它就可以工作。如果我使用 azure 函数执行控制台应用程序,控制台应用程序可以工作,但 C++ exe 会失败,并显示与以前相同的退出代码。
  • 抱歉,我无法解释。可能需要看现场重现。
  • 太糟糕了,还是谢谢。如果您有其他想法,可以联系我们。
  • 您找到解决方案了吗?我也有同样的问题。

标签: c++ azure dll exe azure-functions


【解决方案1】:

根据我刚刚与 Microsoft 支持人员举行的一次会议,无法做到这一点

Azure Functions 是一个非常受控 (sandboxed) 的环境,其中访问 system32 目录会阻止 EXE 操作,尽管必要的 DLL 与 EXE 相邻。

我发现带有 DLL 的 EXE 在 server/core 上运行良好,但在 nanoserver 上无法运行。所以我怀疑 Functions 可能使用 nanoserver,这可能是问题所在。

让您的 C++ 在 nanoserver 上运行可能是通向 Functions 的门户。但是,即使它不能让您使用 Functions,您也可以从 nanoserver 的显着减少占用空间中受益。但是,我对在 nanoserver 上运行的基于 DLL 的 EXE 并不乐观。也许静态链接的 EXE 是一种选择。

实际上,一位同事前段时间在 Functions 中运行了一些控制台应用程序,但它已经停止工作。

编辑:最近才知道 nanoserver 永远不会支持 32 位应用程序(不确定 64 位)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-12
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 2011-11-20
    • 2021-12-04
    相关资源
    最近更新 更多