Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When using Unix I can run several commands at the command line prompt in a row:

# command1; command2; command3

Or even chain them by checking the exit statuses:

# command1 && command2 && command3

Is same possible on Windows XP command prompt?

I often have to run several software building commands on Windows...

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

You've got a few options at the command prompt.

As @barlop mentioned, there's using && to chain commands as long as the previous was successful.

There's also ||, which will stop executing after the first successful command.

Finally, commands can be grouped with parenthesis (), as follows:

C:\>(
echo command 1
echo command 2
)

Grouping can also be used with other commands, such as if or for, allowing for things like:

C:\>for %i in (*.7z) do @(
md "%~ni"
cd "%~ni"
7za.exe x "%~fi"
cd ..
del "%i"
)
share|improve this answer
    
What you said about || being regardless of exit status, is wrong. That also depends on exit status see ntcmds.chm, it says "...Cmd.exe runs the first command, and then runs the second command only if the first command did not complete successfully ...." and try echo a || echo a it just displays a once. –  barlop Aug 11 '11 at 18:34
    
@barlop: Thanks. Edited. –  afrazier Aug 12 '11 at 1:24
    
So Windows seems finally up to Unix here? :-) –  Alexander Farber Aug 12 '11 at 20:29
1  
worth noting, & is regardless of whether the previous was successful. –  barlop Aug 27 '11 at 21:54
add comment

In cmd.exe you can use & for chaining commands (like ; in sh).

echo a & echo b

The && and || operators work too.

share|improve this answer
add comment

ntcmds.chm mentions
under concepts.."cmd shell overview"

&& Use to run the command following && only if the command preceding the symbol is successful

So you can do

C:\>echo a && echo a

added

& is more appropriate as an answer than &&

here from ntcmds.chm

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

&& "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. " (it's a boolean short circuit AND)

|| "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)." (it's a boolean short circuit OR i.e. given the expression "A or B" where A and B are boolean values of TRUE or FALSE, it only needs one to be true, so if A is true it won't go as far as B because it won't need to, in order to make its evaluation)

share|improve this answer
    
Doh! Years of using the command-prompt and I’ve never noticed that cmd supports short-circuit boolean command-chaining. Thanks for pointing out ntcmds.chm. (Aww, edlin is “not available on Windows XP 64-Bit Edition”. Poop.) –  Synetech Aug 12 '11 at 1:35
    
@Synetech: edlin is still a 16-bit MS-DOS program, which cannot work in 64-bit mode. –  grawity Aug 12 '11 at 11:01
    
@grawity, I know, and I miss it (though to be honest, I have completely forgotten how to use it). –  Synetech Aug 13 '11 at 0:16
    
@Synetech: There's always Cygwin ed. –  grawity Aug 13 '11 at 9:51
    
@grawity, well like I said, I don’t even remember how to use Edlin (and besides, I have a DOS boot-disk and DOSBox if I want to). I prefer Notepad2 these days. Though, if 32-bit apps can be emulated and run on 64-bit, and the NTVDM is a 32-bit app that emulates 16-bit, then I can’t help but wonder if the NTVDM can be installed/made to run on 64-bit Windows, thus allowing 16-bit apps on 64-bit. I would assume not, otherwise they would have included it (though not necessarily; devs have been known to force upgrades/updates for business reasons, when not technically required). –  Synetech Aug 13 '11 at 17:14
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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