繁体   English   中英

Azure函数调用二进制可执行文件,将标准输出流式传输到响应(例如,node.js的child_process.spawn)

[英]Azure Functions call a binary executable, stream standard output to response (e.g. child_process.spawn for node.js)

我有一个带有HTTP触发器的Azure函数。 我想通过node.js和/或C#调用一个二进制文件,并将其标准输出流式传输到响应中,同时在该过程中设置HTTP状态代码。

尽管我可能错过了一些简单的方法,但我无法通过AWS Lambda的包装程序使用的常用技术(例如,针对node.js的child_process.spawn)来实现此目的。 通过批处理功能可以做到这一点很简单,除了设置状态码外,我还没有检查响应是否真正流过。 是否有通过node.js和/或C#进行此操作的示例?

亚伦

这应该像在Azure Functions环境之外一样起作用。

关于如何执行过程并在C#/ Node中读取其输出的示例很多,因此我不会花很多时间,但是这里有一个运行dir并打印目录的快速函数示例:

using System;
using System.Diagnostics;

public static void Run(string input, TraceWriter log)
{
    log.Info("Executing");
    using (var process = new Process())
    {
        process.StartInfo.FileName = @"D:\Program Files (x86)\Git\usr\bin\dir.exe";
        process.StartInfo.Arguments = @"D:\home";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.Start();
        string output = process.StandardOutput.ReadToEnd();
        process.WaitForExit();

        log.Info(output);
    }
}

关于流输出,尽管可能,但不建议Azure Functions使用(至少目前不建议这样做)。

希望这可以帮助!

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM