-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[aws-ec2] shellCommand Windows #10684
Comments
I don't understand how the example you gave: // (A)
ec2.InitCommand.argvCommand(['powershell.exe',` '-command "Set-ExecutionPolicy', 'RemoteSigned -Force"'], { key: "00_executionPolicy", waitAfterCompletion: ec2.InitCommandWaitDuration.none() }), Would lead to this being rendered:
If anything, it should lead to this being rendered:
And by the way, judging from the quotes I think you probably meant to do this: ec2.InitCommand.argvCommand([
'powershell.exe',
'-command',
'Set-ExecutionPolicy RemoteSigned -Force'
]); I agree with you there's a bug in the implementation of shellCommand though. |
`InitCommand.shellCommand('abc xyz')` renders to `['abc xyz']` which actually represents an `argv` command of one element, which is treated differently. For example, spaces in it are not parsed, which would be expected for a shell command. The correct rendering for a shell command is a plain string in the `command` property. Fixes #10684.
#10691) `InitCommand.shellCommand('abc xyz')` renders to `['abc xyz']` which actually represents an `argv` command of one element, which is treated differently. For example, spaces in it are not parsed, which would be expected for a shell command. The correct rendering for a shell command is a plain string in the `command` property. Fixes #10684. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
Oh sorry, you are right on the quotes being a little off. So to iterate the issue is purely around shellCommand, specifically when I do this
i get this
but it should be
because within the cfn-init scripts, the "subprocess" Python library is used to invoke commands on the Windows command prompt. When a list of strings is specified in the "command" section, the underlying library attempts to run the entire string specified as a single command with no arguments. This will cause Windows to return an error since it attempts to search for a program with the name of 'powershell.exe -command "Set-ExecutionPolicy RemoteSigned -Force"' as opposed to just 'powershell.exe'. I think argvCommand is good for Windows if it renders to a string too and not string[] with a single element as the same above was happening. |
When using the latest Windows AMI and using shellcommand the commands fail to run with 'The system cannot find the file specified'.
Reproduction Steps
What did you expect to happen?
The command to run successfully
What actually happened?
The error reported was
Environment
Other
I believe the issue is related to shell command outputting to a array with a single element. According to the documentation here if an array is specified every command and parameter needs to be a new element (no whitespace) but if it is a string (as I think shellCommand prefers), it just needs to be a string, so
This will work
This will work
This will NOT work
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: