1

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

Richard
  • 69
  • 6

1 Answers1

3

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.

fpark
  • 2,304
  • 2
  • 14
  • 21
  • For the simple example this is a a valid solution. For commands with user provided arguments we run into issues though - how would we hand them over? In environment variables? – Richard Aug 04 '20 at 21:00
  • Environment variables would be my suggested approach. – fpark Aug 06 '20 at 22:41
  • thanks people - environment variables are an adequate solution to the problem (with some additional escaping). we will go down a different route using powershell -EncodedCommand (i'll answer add our solution to my question) – Richard Aug 07 '20 at 15:48