简体   繁体   English

解析Windows批处理文件的输出以在下一个批处理文件命令中使用

[英]Parsing output of a Windows batch file to use in next batch file command

I am doing some Windows batch file "programming" to use AWS CodeDeploy to register an application revision. 我正在做一些Windows批处理文件“编程”,以使用AWS CodeDeploy注册应用程序修订版。

Here's what I have so far in my batch file: 到目前为止,这是我的批处理文件中的内容:

@echo off
aws --region us-east-1 --endpoint-url https://codedeploy.us-east-1.amazonaws.com deploy push --application-name MyApp1 --s3-location s3://s3-codeDevel-MyApp1.zip --source .\ --description "Application Revision Pushed from Tst"

When I run the command: 当我运行命令时:

aws --region us-east-1 --endpoint-url https://codedeploy.us-east-1.amazonaws.com deploy push --application-name MyApp1 --s3-location s3://s3-codeDevel-MyApp1 --source .\ --description "Application Revision Pushed from Tst"

... by itself, output like this from the command above shows up in the Command Prompt: ...就其本身而言,上述命令的输出将显示在命令提示符中:

To deploy with this revision, run:
aws deploy create-deployment --application-name MyApp1 --s3-location bucket=s3-codeDevel-MyApp1,key=MyApp1.zip,bundleType=zip,eTag=f4f28724b951fdeeee61d57c24ceba99 --deployment-group-name <deployment-group-name> --deployment-config-name <deployment-config-name> --description <description>

I'd like to run another command in the batch file that parses and uses the output above in the next command since the value of "eTag" changes. 我想在批处理文件中运行另一个命令,因为“ eTag”的值发生了变化,因此该文件将解析并在下一个命令中使用上面的输出。

At the end of the day, here's what I want my batch file to look like: 归根结底,这是我希望我的批处理文件如下所示:

@echo off
aws --region us-east-1 --endpoint-url https://codedeploy.us-east-1.amazonaws.com deploy push --application-name MyApp1 --s3-location s3://s3-codeDevel-MyApp1.zip --source .\ --description "Application Revision Pushed from Tst"
aws deploy create-deployment --application-name MyApp1 --s3-location bucket=s3-codeDevel-MyApp1,key=MyApp1.zip,bundleType=zip,eTag=<Parsed from previous command> --deployment-group-name DeploymentGroup --deployment-config-name DeploymentConfigName --description "My Description"

How would I go about getting this done? 我将如何完成这项工作?

a mix of several tricks: 多种技巧的组合:
- run the command and capture last line from output -运行命令并从输出中捕获最后一行
- remove all until eTag -删除所有直到eTag
- fetch first word from "rest" - execute the command with that value -从“ rest”中获取第一个单词-使用该值执行命令

@echo off
set "command=aws --region us-east-1 --endpoint-url https://codedeploy.us-east-1.amazonaws.com deploy push --application-name MyApp1 --s3-location s3://s3-codeDevel-MyApp1 --source .\ --description "Application Revision Pushed from Tst""
for /f "delims=" %%a in ('%command%') do set "line=%%a"
set "line=%line:*eTag=%"
for /f "delims== " %%a in ("%line%") do set "key=%%a"
echo Debug: Key=%key%
aws deploy create-deployment --application-name MyApp1 --s3-location bucket=s3-codeDevel-MyApp1,key=MyApp1.zip,bundleType=zip,eTag=%key% --deployment-group-name DeploymentGroup --deployment-config-name DeploymentConfigName --description "My Description"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM