问题
I can't seem to figure this out.
I am creating a live site and deploying it online
batch file:
START cmd /K "runas /user:administrator & cd C:\users\MyName\dropbox\!!GIT_HUB_REPOS_ALL\tangycode.github.io & hexo generate & hexo serve --draft"
START /wait "" http://localhost:4000/
The thing is running the command hexo generate & hexo serve --draft
takes about 5-10 seconds, time varies. Ideally I want to wait for this to occur before going to live site at http://localhost:4000
Some reason this windows batch command just automatically opens up localhost:4000 right away though
回答1:
I would use /B to stay in the same process and /wait tot wait until the first command is finished. You don't need the /wait in the second line unless there are more commands to follow. If this doens't work, experiment with leaving the cmd /K away. Since runas is an executable and the batch waits until it is finished it's possible you can let away the start command all together.
If all this doesn't work insert 5 ping commands, that is the classic way to wait for ± one second.
START /B /wait "runas /user:administrator & cd C:\users\MyName\dropbox\!!GIT_HUB_REPOS_ALL\tangycode.github.io & hexo generate & hexo serve --draft"
START /B "" http://localhost:4000/
回答2:
I'll take a stab at this, (completely untested).
@Echo Off
(Set SrcDir=%UserProfile%\dropbox\!!GIT_HUB_REPOS_ALL\tangycode.github.io)
If Not Exist "%SrcDir%\" Exit/B
Start "" /D"%SrcDir%" /Wait /B RunAs /User:administrator^
"Cmd /C Start /Wait hexo generate & Start hexo serve --draft"
Start http://localhost:4000/
来源:https://stackoverflow.com/questions/40193625/windows-batch-file-wait-for-command-to-finish