Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows batch file, wait for command to finish?

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

like image 569
Vincent Tang Avatar asked May 22 '26 11:05

Vincent Tang


1 Answers

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/
like image 179
peter Avatar answered May 24 '26 19:05

peter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!