1

I am trying to run a powershell command within a json file which is for cloudformation template. I am getting errors with anything after the pipe(|) symbol.

This is a new script that needs to work for our templates.

"commands": {
                        "UpdateAbsolutePath": {
                            "command": "powershell.exe -Command ((Get-Content -path D:\\Tomcat-8.0\\webapps\\lease_accelerator\\WEB-INF\\web.xml -Raw) -Replace \"LA-AWS-SU1-APP1\",\"LA-AWS-SU2-APP1\") | Set-Content -Path D:\\Tomcat-8.0\\webapps\\lease_accelerator\\WEB-INF\\web.xml"
                        }

I expect it to run fine, but I get the following error:

[DEBUG] No services specified
2019-06-05 13:49:01,572 [DEBUG] Running command UpdateAbsolutePath
2019-06-05 13:49:01,588 [DEBUG] No test for command UpdateAbsolutePath
2019-06-05 13:49:01,618 [ERROR] Command UpdateAbsolutePath (powershell.exe -Command ((Get-Content -path D:\Tomcat-8.0\webapps\lease_accelerator\WEB-INF\web.xml -Raw) -Replace "LA-AWS-SU1-APP1","LA-AWS-SU2-APP1") | Set-Content -Path D:\Tomcat-8.0\webapps\lease_accelerator\WEB-INF\web.xml) failed
2019-06-05 13:49:01,618 [DEBUG] Command UpdateAbsolutePath output: 'Set-Content' is not recognized as an internal or external command,
operable program or batch file.

2019-06-05 13:49:01,618 [ERROR] Error encountered during build of config: Command UpdateAbsolutePath failed
Traceback (most recent call last):
File "cfnbootstrap\construction.pyc", line 513, in run_config
File "cfnbootstrap\construction.pyc", line 125, in run_commands
File "cfnbootstrap\command_tool.pyc", line 113, in apply
ToolError: Command UpdateAbsolutePath failed
2019-06-05 13:49:01,618 [ERROR] -----------------------BUILD FAILED!----- 
-------------------
2019-06-05 13:49:01,618 [ERROR] Unhandled exception during build: Command UpdateAbsolutePath failed
Traceback (most recent call last):
File "cfn-init", line 123, in <module>
File "cfnbootstrap\construction.pyc", line 117, in build
File "cfnbootstrap\construction.pyc", line 502, in build
File "cfnbootstrap\construction.pyc", line 513, in run_config
File "cfnbootstrap\construction.pyc", line 125, in run_commands
File "cfnbootstrap\command_tool.pyc", line 113, in apply
ToolError: Command UpdateAbsolutePath failed`
0

1 Answer 1

3

Enclose the command within double quotes or add a ^ before the pipe symbol.

Some valid and non-valid examples:

> powershell -Command Write-Output "OK" | Out-String
'Out-String' is not recognized as an internal or external command, operable program or batch file.
> powershell -Command Write-Output "OK" ^| Out-String
OK
> powershell -Command 'Write-Output "OK" | Out-String'
'Out-String' is not recognized as an internal or external command, operable program or batch file.
> powershell -Command "Write-Output `"OK`" | Out-String"
OK
> powershell -Command { Write-Output "OK" | Out-String }
'Out-String' is not recognized as an internal or external command, operable program or batch file.
> powershell -Command "& { Write-Output "OK" | Out-String}"
OK
Sign up to request clarification or add additional context in comments.

1 Comment

What's the meaning of the ^ symbol before the pipeline symbol?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.