0

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
Zakaria Shahed
  • 2,589
  • 6
  • 23
  • 52
  • What is sudo here? Is that a Windows sudo.exe, or are you running the Windows 10 Linux subsystem? Are these commands running in a WSL bash script? What does this have to do with the CMD shell? – Eryk Sun Oct 04 '17 at 07:27
  • I am trying to install docker on my windows pc and in documentation they mention this cmd for windows and i want to run it by one click – Zakaria Shahed Oct 04 '17 at 07:29
  • Is this Windows-related? If not, please remove the tag [tag:cmd]! – aschipfl Oct 04 '17 at 08:13

2 Answers2

2

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

Fluttershy
  • 64
  • 5
0

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)

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • Don't forget to `dos2unix` your shell script as BASH is not able to handle windows EOL pattern. – Gaétan RYCKEBOER Oct 04 '17 at 07:50
  • You need to enable bash from the windows features in order to have Bash shell enabled. Its a feature in windows 10. Or else you use cmd prompt and use the second approach. – Ranadip Dutta Oct 04 '17 at 17:33
  • Yes it is. Or use an external shell like http://cmder.net, or gnu utilities. Hopefully, bash exists since much more than microsoft decided to add it to windows… ! I presume the author of the question already has a bash installed, since he has a sudo, and various shell commands in his script :) – Gaétan RYCKEBOER Oct 06 '17 at 08:50