Skip to content
Advertisement

Azure Batch Service: Passing Arguments via Command Line into Application Package on Linux/Ubuntu

Given the following C#/.NET console application running on my Azure Batch Pool/Task:

class Program
{
    static async Task Main(string[] args)
    {
        try
        {
            Console.WriteLine(args[0]);
            Console.WriteLine(args[1]);
        }
        catch
        {
            Console.WriteLine($"Could not parse arguments");
        }
    }
}

How can I pass the args when adding a command line to my tasks in a Linux/Ubuntu VM. I have tried the following with no success:

/bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0/Program -args ‘arg1’ ‘arg2’

/bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0/Program -args ‘arg1’, ‘arg2’

/bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0/Program ‘arg1’ ‘arg2’

/bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0/Program ‘arg1’, ‘arg2’

/bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0/Program -i ‘arg1’ ‘arg2’

/bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0/Program -i ‘arg1’, ‘arg2’

I am able to run the application but the arguments are not passed in and I only get to the “Could not parse arguments” output…

Advertisement

Answer

After throwing every variation possible at this (and looking at this example) it looks like you have to concatenate the string value of the package name with the args to the environment variable in a certain way to make sure the parameters carry through to the command.

Here is what finally did it for me

/bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0"/Program 'arg1' 'arg2'"

Hope this helps anyone who is looking for it!

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement