Windows Tip Sheet
Do More with More
Where a batch file might seem just a bit over the top, try this nifty trick with the More command.
- By Jeffery Hicks
- 08/15/2007
You’re probably familiar with the More command, which you use to page output. But there’s another version you may not be familiar with. When you are at a command prompt and type an opening parenthesis,
(, followed by Enter, you will get a special prompt that looks like this:
C:\>(
More?
At the prompt type a command. Each new line will allow you to enter another command. Type a closing parenthesis, ), to get back to the main prompt. Once you hit Enter, all of your commands will be executed in sequence.
Try it out. Open a command prompt and type or simply copy and paste at a CMD prompt:
(
Echo %windir%
Echo I am a command
Time /t
Date /t
)
All four commands will execute. As you see, this is like creating a batch file -- without the file! I’d say it is also equivalent to creating a script block in PowerShell, except this version is interactive.
Here’s another example for you to try:
(
cls
Echo This is %computername%
echo It is now %date% %time%
echo Free space on drive C:
dir c:\ | find /i "free"
)
You can use this technique to redirect output from multiple commands to the same file. When you get to the closing parenthesis, add > filename, like this:
(
dir s:\*.wsf
dir f:\sa\*.*
dir c:\temp\*.vbs
) >results.txt
I can very easily redirect the output of three different DIR commands to the same file.
Tech HelpJust An
E-Mail Away |
Got a Windows, Exchange or virtualization question
or need troubleshooting help? Or maybe you want a better
explanation than provided in the manuals? Describe
your dilemma in an e-mail to the MCPmag.com editors
at [email protected];
the best questions get answered in this column and garner
the questioner with a nifty Redmond T-shirt.
When you send your questions, please include your
full first and last name, location, certifications (if
any) with your message. (If you prefer to remain anonymous,
specify this in your message, but submit the requested
information for verification purposes.) |
|
|
Spelling counts and typing mistakes can’t be fixed. There’s no way to go back once you’ve moved to the next line. But if you need to abort what you’re doing, use Ctrl+C before you put in the closing parenthesis.
So the next time you have multiple commands you need to run -- perhaps a series of scripts -- you don’t need to figure out how create a batch file. Just do more!
About the Author
Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.