Nayden Van
Nayden Van

Reputation: 1569

Azure function exe

Sorry for the basic question but i have a problem and i canot find the solution to it.

I have a exe application that i would like to lunch with an azure function and store the result in a blob storage, using a TimeTrigger to make it run once every 24 hours.

I found this one here:

using System;

public static void Run(TimerInfo myTimer, TraceWriter log)
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = @"<path to file>";
    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}");
}

but i was wondering how can i save this output to a specific blob storage that i already have?

I am so sorry about this question but i am totally new to azure functions and c#

Upvotes: 0

Views: 389

Answers (1)

Bryan Lewis
Bryan Lewis

Reputation: 5977

If your external exe process is working and the value of the "output" string is correct, and all you want to do is save it to blob storage, then you can simply add a blob output binding. See the MS docs for full details: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-output?tabs=csharp

But essentially you will have your blob output binding in the function's parameters:

public static void Run(TimerInfo myTimer, [Blob("mycontainer/{name}", FileAccess.Write)] Stream myOutputBlob, TraceWriter log)

See the docs if you have not setup a output binding connection string before. myOutputBlob is a stream that you can then write to in order to save your output to blob storage:

byte[] bytes = Encoding.ASCII.GetBytes(output);
await myOutputBlob.WriteAsync(bytes);

Note, you can use myOutputBlob.Write() as an alternative if you don't want to use async, but async is recommended for blob storage I/O.

Upvotes: 0

Related Questions