执行第一个命令后,批处理文件停止执行

son*_*rma 2 batch-file

我创建了一个包含以下内容的批处理脚本.但是脚本在执行第一个语句后终止.我已经google了很多但是找不到任何有用的东西.但是个别陈述可以单独执行.PFB剧本

任何建议表示赞赏.

set AWS_SNAPSHOT_KEEP=1

:: Create a file with all attached volumes
::ec2-describe-volumes|find /i "attached">%EC2_HOME%\Volumes.txt

:: Create snapshot for this volume
for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do ec2-create-snapshot %%s

:: Find old snapshots for this volume.
for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do ec2-describe-snapshots --filter "volume-id=%%s">%EC2_HOME%\Snapshots.txt

::Copy Snapshot across multiple regions.
for /f "tokens=2" %%s in (%EC2_HOME%\Snapshots.txt) do ec2-copy-snapshot -r us-west-2 -s %%s -region us-east-1 

:: Loop over old snapshots, skip the first 1, delete the rest
for /f "tokens=2 skip=%AWS_SNAPSHOT_KEEP%" %%s in (%EC2_HOME%\snapshots.txt) do ec2-delete-snapshot %%s
Run Code Online (Sandbox Code Playgroud)

谢谢和问候,Jyoti

chw*_*arr 6

ec2-create-snapshot如果他们是我在网上找到的Amazon EC2 API工具,那么他们自己就是批量脚本.他们碰巧在完成后打电话exit.这也是退出批处理脚本.

相反,请尝试call在ec2命令之前使用.

for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do call ec2-create-snapshot %%s

根据需要应用于其他ec2命令.

有关详情请参阅的输出help exithelp call.

批量睡眠的常用习惯是ping本地机器:

@ping -n 2 -w 1000 127.0.0.1 > NUL
Run Code Online (Sandbox Code Playgroud)

通过对本地机器进行两次ping操作,每次间隔1秒,这会"休眠"约2*1000毫秒= 2秒.根据需要添加.