How To Run Two Commands In One Line In Windows CMD

bardimin pic

Written by Bardimin

On July 7, 2022
Home » Blogs » Windows » Tips and Tricks » How To Run Two Commands In One Line In Windows CMD

You can run multiple commands in one in the (CMD).

Using conditional processing symbols, you can create multiple commands with just one or . When you use the conditional processing symbol to execute multiple commands, the instructions to the right of the conditional processing symbol act on the results of the command to the left of the conditional processing symbol.

For example, you can run a command only if the previous command failed. Alternatively, perform the command only if the previous command was successful.

Running some commands with the character “&”

command1 & command2
echo foo & echo bar

The “&” character can separate multiple commands on one command line. Cmd.exe will run the first command, and then the second command.

Running some commands with the character “&&”

command1 &&command2
echo foo &&amp amp echo bar

Using the “&&” character, CMD will execute the first command (command1) first. If the first command completes successfully, a new second command (command2) will be executed.

Run some commands with the character “|| “

command1 II command2
echo foo || echo bar

If using the “||” character, CMD will run the first command (command1). The second command (command2) will only be executed if the first command did not complete successfully (received an greater than zero).

Note:

Ampersands (&), pipes (|), and parentheses () are special characters that must be preceded by an escape character (^) or quotation marks when you pass them as arguments.

Echo THIS ^& THAT
Echo Heading1 ^| heading2 ^| heading3

If a command successfully completes the operation, it returns zero exit code (0) or no exit code. For more information about exit codes.

Latest Articles

Limit Your Privacy Data Collection in Windows 11

Limit Your Privacy Data Collection in Windows 11

People are increasingly aware of their privacy due to the use of the internet and social media platforms. Windows 11 users need to understand that the operating system actively retrieves data from many web-based sources. Whenever someone establishes a connection to a...

How to Know When Your Password Was Last Changed on Windows

How to Know When Your Password Was Last Changed on Windows

One easy method to ensure the security of user accounts is to enforce policies that require periodic password changes. One way to prompt users to change their passwords is to notify them when their passwords are about to expire. While it may not always be necessary,...

17 Tips and Tricks for Customizing Windows via Registry

17 Tips and Tricks for Customizing Windows via Registry

Before you edit or modify the Windows registry, back up from that registry. Fatal errors in changing the registry can cause the operating system to not run normally. In some cases, registry damage can only be repaired by reinstalling the operating system and resulting...

Portable BloatyNosy 0.80 – Debloat and Customize Windows 11

Portable BloatyNosy 0.80 – Debloat and Customize Windows 11

BloatyNosy is a free app that lets you remove the built-in junk apps in Windows that improve your Windows performance. The application is available in portable and installer versions. If you are looking for a free Debloat tool, then you might need to try BloatyNosy...

The sequence of Windows boot processes from zero to ready

The sequence of Windows boot processes from zero to ready

Have you ever wondered how exactly the Windows boot process happens? What processes happen in the background when you press the power button until Windows is ready for you? If yes, then you are in the right place. In this article, Bardimin will explain how all these...