91

I know Unix has the following command which can execute multiple commands in a single line, how can I do this in DOS?

command1 ; command2 ; command3 ...
3
  • 6
    You can chain commands by using an ampersand &, e.g. echo Hello & echo World Commented Dec 5, 2012 at 8:43
  • Or you could get cygwin, and have unix cmds on windows :-) Commented Dec 5, 2012 at 8:45
  • In actual DOS or the Windows command-prompt? Commented Dec 6, 2012 at 18:32

1 Answer 1

191

Googling gives me this:


Command A & Command B

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


Command A | Command B

Execute Command A, and redirect all its output into the input of Command B


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, evaluate the exit code of this command and if it's anything but 0, only then execute Command B


Sign up to request clarification or add additional context in comments.

7 Comments

Now, in 2014, googling gives me this.
Google doesn't answer questions, Google finds people's answers to questions. If no one answers the question first, Googling is pointless! :-)
I just found this googling and it helped me :)
If I define some aliases (e.g. doskey a=echo a doskey b=echo b) I can't run a && b. Is there a way around it?
You know honestly the way the stackoverflow community punishes unpopular questions and jumps on people who asks duplicate questions makes asking a question in a comment make a lot more sense. Granted, people should look in stackoverflow first before asking a question, but some people suck at searching and sometimes searches bring newer questions up first (like this one). I guess that's a problem with google.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.