首页 > 解决方案 > 如何在 Azure Batch 任务中调用预安装的应用程序?

问题描述

我将 sqlcmd 实用程序安装到 Azure Batch 节点(这是常规的 Windows VM)。所以,我在这个虚拟机上有 bcp 实用程序。如何在 Azure Batch 作业中指定 bcp.exe 的路径?

 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);
}

指定完整路径是否正确

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

标签: azureazure-virtual-machineazure-batch

解决方案


您有几种方法可以在不同的路径中启动命令:

  1. PATH 在环境变量中指定可执行目录。确保您使用的是 shell 命令 ( cmd.exe)。
  2. 使用可执行文件将您的工作目录更改为正确的目录
  3. 根据您在任务命令行中的帖子指定完整路径。

对于您的特定情况,您的命令格式错误。执行时cmd.exe,应该是cmd.exe /c <your command>.


推荐阅读