[英]How Can I Write a Batch File Where I Start one Program and When that Program Finishes or Closes, Start Another
For example: 例如:
@echo off
start C:\Windows\system32\dfrgui.exe /C
Wait for defragmentation to finish. 等待碎片整理完成。
start C:\"Program Files (x86)"\CCleaner\CCleaner.exe /AUTO
Wait for CCleaner to finish. 等待CCleaner完成。
start C:\Windows\system32\cleanmgr.exe /sagerun:1
and so on.. You get the point. 依此类推..您明白了。 How I can do this?
我该怎么做? Thanks.
谢谢。
Start can take a command line argument /WAIT eg 开始可以使用命令行参数/ WAIT,例如
@echo off
title Test cmd start
start /WAIT wait.cmd 5
start /WAIT cmd /k echo launched second command
pause
This simple example uses another script I have written (wait.cmd shown below) as the first command executed, as you will see if you test this with the /WAIT option specified the script allows the first command to finish before continuing: 这个简单的示例使用了我编写的另一个脚本(如下所示的wait.cmd)作为执行的第一个命令,因为您将看到是否使用指定的/ WAIT选项对其进行测试,该脚本允许第一个命令在继续之前完成:
@echo off
rem call with # of seconds to wait
set /a secs=%1
set /a ms=%secs%*1000
echo Process will wait for %secs% seconds and then continue...
ping 1.1.1.1 -n 1 -w %ms% > nul
echo.
exit
As a side note if you open a cmd session you can find out about the arguments that a command such as start accepts eg 作为附带说明,如果您打开cmd会话,则可以找到有关命令(例如start)接受的参数的信息,例如
Update following comment 更新以下评论
So to adapt the commands you listed in your question to finish before starting the next command in the script you could use: 因此,为了在脚本中开始下一个命令之前使问题中列出的命令适应完成,可以使用:
@echo off
start /WAIT C:\Windows\system32\dfrgui.exe /C
start /WAIT C:\"Program Files (x86)"\CCleaner\CCleaner.exe /AUTO
start /WAIT C:\Windows\system32\cleanmgr.exe /sagerun:1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.