如何在Azure Batch任务中调用预安装的应用程序?

huangapple go评论65阅读模式
英文:

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

问题

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

使用以下代码:

using (BatchClient batchClient = BatchClient.Open(cred))
{
    string jobId = "1";
    CloudJob job = batchClient.JobOperations.GetJob(jobId);
    job.Commit();
    
    string taskCommandLine = "cmd c/ 'D:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\0\\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 = "cmd c/ 'D:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\0\\Tools\\Binn\\bcp.exe'";
英文:

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\0\\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\0\\Tools\\Binn\\bcp.exe'");

答案1

得分: 2

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

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

对于你的特定情况,你的命令格式不正确。在使用cmd.exe执行时,它应该是 cmd.exe /c <your command>

英文:

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 &lt;your command&gt;.

huangapple
  • 本文由 发表于 2020年1月6日 18:11:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/59610182.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定