Skip to content

Commit 35bfa60

Browse files
authored
Remove trailing empty argument in ContainerCommand
The New-AzContainerGroup -Command argument adds an extra empty argument to the end of the commands. This is because Parser.ParseInput will return <EOF> as the final token. This means any programs using command arguments will get an extra empty argument passed in. The Python-based az cli does not do this. To repro: 1. Create an app that shows how many arguments were passed into it. For example in .net core: ``` class Program { static void Main(string[] args) { Console.WriteLine("I have {0} arguments", args.Length); } } ``` 2. Add this to a container and push to a registry. 3. Run the container as an ACI using powershell ``` New-AzContainerGroup -ResourceGroupName test -Name bugtest -Image showargImage -OsType Linux -Command "dotnet showargs.dll one two three" ``` 4. Examine the logs: ``` Get-AzContainerInstanceLog -ResourceGroupName test -ContainerGroupName bugtest I have 4 arguments ``` 5. Run the image using the az CLI ``` az container create --resource-group test --name bugtest2 --image showargImage --command-line "dotnet BugTest.dll one two three" ``` 6. Examine the output ``` az container logs --resource-group akstest --name bugtest2 I have 3 arguments ```
1 parent 3ef406a commit 35bfa60

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/ContainerInstance/ContainerInstance/Commands/NewAzureContainerGroupCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public override void ExecuteCmdlet()
263263
{
264264
throw new ArgumentException($"Invalid 'Command' parameter: {string.Join("; ", errors.Select(err => err.Message))}");
265265
}
266-
creationParameter.ContainerCommand = tokens.Select(token => token.Text.Trim('\'', '"')).ToList();
266+
creationParameter.ContainerCommand = tokens.Select(token => token.Text.Trim('\'', '"')).Where(token => !string.IsNullOrEmpty(token)).ToList();
267267
}
268268

269269
creationParameter.Validate();

0 commit comments

Comments
 (0)