在 Azure 函数中使用 DLL 运行 .exe

Chr*_*ris 5 c++ dll exe azure azure-functions

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

就像在Azure Function中的 Post Run .exe 可执行文件中一样,建议我准备好 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}");
}
Run Code Online (Sandbox Code Playgroud)

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

有没有人有类似的问题?

谁能帮我?谢谢!

Pet*_*r L 0

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

Azure Functions 是一个高度受控的(沙盒)环境,尽管必要的 DLL 与 EXE 相邻,但对 system32 目录的访问会阻止 EXE 操作。

我发现带有 DLL 的 EXE 在服务器/核心上运行良好,但在nanoserver上不起作用。所以我怀疑 Functions 可能使用 nanoserver,这可能是问题所在。

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

一位同事实际上在不久前在 Functions 中运行了一些控制台应用程序,但后来它停止工作了。

编辑:最近刚刚了解到 Nanoserver 将永远不会支持 32 位应用程序(不确定 64 位)