简体   繁体   中英

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.

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.

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
- fetch first word from "rest" - execute the command with that value

@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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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