Reputation: 69
When using windows container workloads on Azure Batch quotes are stripped from command line arguments if they do not contain a space.
We are using the newest C# SDK 13.0.0 and node VMs SKU windows server 2019 with containers.
Repro:
Create job and a task running inside a docker container (e.g. based on the docker image mcr.microsoft.com/windows/servercore:ltsc2019)
use command line of cmd /S /C mkdir "c:/foo"
- see that inside the docker container the command is executed as cmd /S /C mkdir c:/foo
- which will fail.
The same issue is described in this open containers PR: https://github.com/opencontainers/runtime-spec/commit/deb4d954eafc4fc65f04c00a08e08c3e69df32d0
Edit: I realized that this was more as statement than a question... so here is the question: What is a workaround/fix for this behavior?
Edit powershell -EncodedCommand Solution:
I accepted the environment variable solution but we are using a different one.
We use "https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe?view=powershell-5.1#-encodedcommand-base64encodedcommand
" - doing so hides quotes and backslashes from CommandLineToArgsvW and docker - meaning the commandline gets put together properly inside the docker container on the azure batch vm. (In C# this is done by var base64EncodedCmd = System.Convert.ToBase64String(System.Text.Encoding.Unicode.GetBytes(cmd));
) Take care to escape powershell properly as well. e.g. the encoded command could be something lik "& my.exe --% --input \\\"userprovidedparam\\""
(using powershells "stop parsing" --%) otherwise e.g. a value of $(Get-Date) would be evaluated
Upvotes: 1
Views: 179
Reputation: 2369
Given this is an issue with the runtime, a potential workaround is to create a .cmd
or .bat
file that contains the commands you would like to run. You can associate this file as a ResourceFile or bake it into a custom container.
Upvotes: 3