1

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'");

1 Answers1

2

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>.

fpark
  • 2,304
  • 2
  • 14
  • 21
  • Hi, @fpark. So, I created new env var on vm 'set bcp_path=D:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\' My taskCommandLine 'string taskCommandLine = String.Format("cmd.exe c/ %bcp_path%\\bcp.exe \"select * from [myAzureSQLBD].[dbo].[Table]\" queryout %AZ_BATCH_NODE_SHARED_DIR%\\items.csv -c -t, -T -S myAzureSQLServer.database.windows.net");' I am trying to export sql table to items.csv file. Is it correct taskCommandLine? Whan, I am running task it stucks in running state. How I can monitoring task executing? – Artem Beziazychnyi Jan 07 '20 at 11:42
  • 2
    As per answer, your command is malformed. It should be `cmd.exe /c ` not `cmd.exe c/ `. – fpark Jan 08 '20 at 17:11
  • Thanks a lot, @fpark!!! It is working now. I replaced `c/` with `/c`. – Artem Beziazychnyi Jan 09 '20 at 18:04