In the DOS command line, I used to be able to enter ¶ between commands to put multiple commands on one line.

For example, instead of typing

c:\> cls
c:\> cd

I could enter

c:\> cls¶cd

Has this functionality been removed or has this been replaced by something else?

How can I run multiple commands from one line?

link|improve this question
cls && cd works in the WIN7 cmd.exe, but I'm not sure if it works in a dos shell – user685684 Dec 16 '11 at 14:50
feedback

migrated from stackoverflow.com Dec 16 '11 at 21:48

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 5 down vote accepted

Use &.

From the documentation:

command1 & command2 : Use to separate multiple commands on one command line. Cmd.exe runs the first command, and then the second command.

command1 && command2 : Use to run the command following && only if the command preceding the symbol is successful. Cmd.exe runs the first command, and then runs the second command only if the first command completed successfully.

command1 || command2 : Use to run the command following || only if the command preceding || fails. Cmd.exe runs the first command, and then runs the second command only if the first command did not complete successfully (receives an error code greater than zero).

(command1 & command2) : Use to group or nest multiple commands.

command1 parameter1;parameter2: Use to separate command parameters.

link|improve this answer
feedback

cls & cd

All you need is &

As others have stated, && will only execute the second command if the first was successful.

|| will execute the second command if the first failed.

Have fun!

link|improve this answer
Thanks. I like that command separator a hell of a lot better as well. – John MacIntyre Dec 16 '11 at 14:51
1  
That doesnt display the cd command, plus when I tried it I couldn't move to another directory. – Neil Knight Dec 16 '11 at 14:51
Wait ... cd is never run. – John MacIntyre Dec 16 '11 at 14:51
Whoa, I was in linux for a second. My fault, fixed. – luastoned Dec 16 '11 at 14:53
feedback

&&. The double ampersand actually performs error checking. If the commands to the left of the && don't return with the expected result, the commands on the right aren't executed.

cls && cd

If you want to run the commands on both sides of the &&, use a single ampersand.

cls & cd

link|improve this answer
-1 && will run the second command only if the first is successful. – dogbane Dec 16 '11 at 14:54
@dogbane: Please see my answer – Neil Knight Dec 16 '11 at 14:56
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.