92

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 ...
IInspectable
  • 46,945
  • 8
  • 85
  • 181
zdd
  • 8,258
  • 8
  • 46
  • 75

1 Answers1

192

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


Extreme Coders
  • 3,441
  • 2
  • 39
  • 55
SidR
  • 2,964
  • 1
  • 18
  • 32
  • 53
    Now, in 2014, googling gives me this. – philshem Oct 16 '14 at 13:17
  • 4
    Google doesn't answer questions, Google finds people's answers to questions. If no one answers the question first, Googling is pointless! :-) – SharpC Sep 18 '15 at 12:13
  • 3
    I just found this googling and it helped me :) – Yíu Nov 27 '15 at 00:49
  • 1
    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? – Yaniv Aug 23 '16 at 16:49
  • @Yaniv Ask this as a new question (clicking the "Ask Question" button on the top right), not as a comment. – peterh Oct 05 '16 at 15:37
  • 6
    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. – ggb667 Jan 18 '17 at 18:29
  • For posterity: `errorlevel` (aka `Exist status`) and `exit code` are synonymous. They refer to the value returned by a child process to a parent process (e.g., the OS shell and the program called from the shell). The former are terms used with DOS-OS's and the latter is associated with Unix systems. See [Wiki: Exit Status](https://en.wikipedia.org/wiki/Exit_status) – Minh Tran Dec 01 '17 at 02:16