AWS Run Command act different than running on server locally

百般思念 提交于 2019-12-31 07:06:21

问题


I am having problems running commands on an EC2 Instance from my Bamboo server. I have a command generated from the Run Command in the AWS Console. I place that command in a script on my bamboo server and run it:

aws ssm send-command --document-name "AWS-RunPowerShellScript" --targets '{\"Key\":\"tag:Name\",\"Values\":[\"Auto-Scaling-Group\"]}' --parameters '{\"commands\":[\"$fileEXE = \\\"C:\\\\Program Files (x86)\\\\NUnit\\\\NUnit.ConsoleRunner.3.7.0\\\\tools\\\\nunit3-console.exe\\\\\\\"\",\"$testDll = \\\"C:\\\\TestFramework\\\\TestFramework\\\\Tests\\\\bin\\\\Debug\\\\TESTS.dll\\\"\",\"[System.Diagnostics.Process]::Start($fileEXE,$testDll)\"]}' --comment "Run Test UI Testing" --timeout-seconds 600 --region us-east-1

It does run the tests. But it runs the Chrome.exe browser AND the chromedriver.exe as background processes. This throws a NoSuchWindowException because there is no browser showing up...

I can run the same command in PowerShell on the instance locally: (*Note that this is the same command I pasted into the Run Command console to generate the code mentioned above.)

$fileEXE = "C:\Program Files (x86)\NUnit\NUnit.ConsoleRunner.3.7.0\tools\nunit3-console.exe\"
$testDll = "C:\TestFramework\TestFramework\Tests\bin\Debug\TESTS.dll"
[System.Diagnostics.Process]::Start($fileEXE,$testDll)

It works just fine. chromedriver.exe is a background process and chrome.exe (the browser) is a regular app that works like normal.

I believe my problem is how Run Command is running my test program.

What is the difference between Run Command (send-command) and running the PowerShell commands locally? Shouldn't it do the same thing?


回答1:


I think there is a mess up with quotes and the way how they're escaped.

See: How to escape a double quote inside double quotes?

This version should look much simpler:

CMD='$fileEXE = "C:\Program Files (x86)\NUnit\NUnit.ConsoleRunner.3.7.0\tools\nunit3-console.exe";'
CMD+='$testDll = "C:\TestFramework\TestFramework\Tests\bin\Debug\TESTS.dll";'
CMD+='[System.Diagnostics.Process]::Start($fileEXE,$testDll);'

aws ssm send-command --document-name "AWS-RunPowerShellScript" \
  --filters "Name=tag:Name,Values=Auto-Scaling-Group" \
  --comment "Run Test UI Testing" --timeout-seconds 600 --region us-east-1 \
  --parameters commands="'$CMD'"

Note: Run it in the Bash shell.



来源:https://stackoverflow.com/questions/45765769/aws-run-command-act-different-than-running-on-server-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!