Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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

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

    
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
up vote 9 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.

share|improve this answer

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!

share|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

&&. 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

share|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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .