How do I run two commands in Windows CMD?

﹥>﹥吖頭↗ 提交于 2021-01-29 09:00:00

问题


I have two commands in that I need to run on CMD.I want to make a bash file so that I can run commands in one click.And I want to wait some time for executing 1st one completely

sudo docker run -d --link selenium-hub:hub selenium/node-chrome
sudo docker run -d --link selenium-hub:hub selenium/node-firefox

回答1:


You can do this with "&&"

you could put this in a "script.bat":

sudo docker run -d --link selenium-hub:hub selenium/node-chrome && sudo docker run -d --link selenium-hub:hub selenium/node-firefox

And if you want to wait between the commands, use something like this:

sudo docker run -d --link selenium-hub:hub selenium/node-chrome && sleep 1000 && sudo docker run -d --link selenium-hub:hub selenium/node-firefox

You can chain this indefinetely. For example you could do sudo apt update && sudo apt upgrade && sudo apt autoremove

As stated in another answer, && this will check if the previous command was successful. If you don't want any validation you have to use ; for BASH or & for CMD




回答2:


create a file with .sh and put the content as :

#!/bin/bash
sudo docker run -d --link selenium-hub:hub selenium/node-chrome 
sudo docker run -d --link selenium-hub:hub selenium/node-firefox

In windows just Logical AND will work:

sudo docker run -d --link selenium-hub:hub selenium/node-chrome && sudo docker run -d --link selenium-hub:hub selenium/node-firefox

Refer this LINK:

Command A && Command B

Execute Command A, evaluate the errorlevel after running and if the exit code (errorlevel) is 0, only then execute Command B

Command A & Command B

Execute Command A, then execute Command B (no evaluation of anything)



来源:https://stackoverflow.com/questions/46558111/how-do-i-run-two-commands-in-windows-cmd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!