Search code examples
azureazure-virtual-machineazure-batch

How I can call pre-installed application in Azure Batch task?


I installed sqlcmd utility into Azure Batch Node (this is regular windows VM). So, I have bcp utility on this VM. How I can specify path to bcp.exe in Azure Batch job?

 using (BatchClient batchClient = BatchClient.Open(cred))
{
    string jobId = "1";
    CloudJob job = batchClient.JobOperations.GetJob(jobId);
    job.Commit();        

    string taskCommandLine = String.Format("cmd c/ 'D:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\130\\Tools\\Binn\\bcp.exe'");

    string uniqueIdentifier = Regex.Replace(Convert.ToBase64String(Guid.NewGuid().ToByteArray()), "[/+=]", "");
    string taskId = String.Format(name.Replace(".", string.Empty) + "-" + uniqueIdentifier);

    CloudTask task = new CloudTask(taskId, taskCommandLine);
    task.UserIdentity = new UserIdentity(new AutoUserSpecification(elevationLevel: ElevationLevel.Admin, scope: AutoUserScope.Task));

    batchClient.JobOperations.AddTask(jobId, task);
}

Is it right way to specify full path like

string taskCommandLine = String.Format("cmd c/ 'D:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\130\\Tools\\Binn\\bcp.exe'");

Solution

  • You have a few ways to launch a command in a different path:

    1. Specify the executable directory in the PATH environment variable. Ensure you are using a shell command (cmd.exe).
    2. Change your working directory to the correct directory with the executable
    3. Specify the full path as per your post in the task command line.

    For your particular case, your command is malformed. When executing with cmd.exe, it should be cmd.exe /c <your command>.