Some command-prompt tricks
In Bryce’s recent postings on http://www.technibble.com/scripting-your-own-computer-repair-tools-pt4/ he has provided some great information about batch scripting.
In the process, I blurted out that you can chain DOS commands together, but had to recant my statements..
There are several ways to do this, however:
First one is a re-direct:
> Re-direct the screen output to a file like the example:
DIR C: > somefile.txt
What is this doing? This is taking what is being shown on the screen and re-directing the output to a file called: somefile.txt
Caveat: With one “>” this or any other command re-directed to this file will be over-written each and every time. If you want to append (add to) the end of the file, just simply double it up:
“>>” like the example:
DIR C: >> somefile.txt
Next is a pipe “|” and is used for things like:
DIR C:\windows | more
Yawn, yeah I know that I can also do:
DIR /p C:\windows
and get the same results..
However, you can pass through things like (Be very careful here, please!!):
ECHO y|DEL C:\somedir\*.txt
So, what this does is to take the y (or yes response) and “pipe” it through the del command.
There are some other things that are a bit obscure that can be done too. Your mileage may vary..
One command to do two actions.. Let’s see if we can do a Dir on two folders..
DIR C:\windows;”C:\program files”
Note: This is all one command-line command. Pretty cool huh? This does a Dir on both the C:\Windows and the C:\Program Files in one command!!
Two commands to do at a one time.. Hmmm..
Now, let’s try to do two commands in one command from the command-line:
TYPE C:\boot.ini&DIR c:
Note: This is all one command. This does Type the contents of the boot.ini file and then a Dir on C:\ drive in one command!! It is important to note that if you do a DIR with an /s, you will traverse (go through all of the directories) in the C:\ drive and you will get a ton of results.
Caveat: If you use this in a batch file, you will need to do the following:
TYPE C:\boot.ini&&DIR C:
Note: the double “&&” to chain these two commands together in a batch file.
Note #2: You cannot do the following with XCOPY, for example..
XCOPY C:\Windows;”C:\Program Files” D:\SomeFolder
Filed under: Scripting | Tagged: batch | Comments Off