There are multiple ways to run multiple commands on Command line in Windows DOS

You can use either single (&) or double(&&) ambersand to run multiple commands in a single line.

In either cases, command execution starts from left to right.

 command1 & command 2

 command1 && command2

command2 waits for exit status of command1.

Let’s see the difference

&: command2 runs after command1 runs. and command2 always executed if command1 returns error or not &&: command2 runs only if command1 execuion succesfull. if command1 returns error, command2 is not executed comm

command throws an error or failed means, error code always greater than zero, for succesful execution error code is zero.

C:\>dr & echo succes
'dr' is not recognized as an internal or external command,
operable program or batch file.
succes

In case of single ampersand,provided first command as an dr instead of dir an error command. Second command print success, So first command throws an error, second command executed.

C:\>dr && echo succes
'dr' is not recognized as an internal or external command,
operable program or batch file.

Used the same example with double &&. second command is not execute after first command failed,

There are some other ways to executes the multiple commands in a single line

  • double pipe(||): It behaves same as &&
  • Comma or semi colon(,,;): It behaves same as &
C:\>dr ; echo succes
'dr' is not recognized as an internal or external command,
operable program or batch file.

C:\>dr , echo succes
'dr' is not recognized as an internal or external command,
operable program or batch file.

C:\>dr || echo succes
'dr' is not recognized as an internal or external command,
operable program or batch file.
succes