Pages

Batch Programming Lesson 4

 Redirect the output of one command to other file


     To redirect the output of one command to other file, the ‘>’ and ‘<’ command is used. For example the below command is used to print the text “hello redirection” to a notepad file named “first.txt”.

     C:\>echo hello redirection > first.txt
   C:\>

   As we already have seen that the ‘echo’ command is used for printing the given text on the screen, here by using the redirection operator ‘>’ we are redirecting the output of the command to a text file. It will create a new text file even it wasn’t already there.
       The below command is used for performing the same operation but the redirection happens to word document,

      C:\> echo hello redirection > first.doc

The Tilde (~)


     The tilde ‘~’ operator is a unary operator that is used for shortening the long directory names.

       The tilde operator can be used after 6 consecutive characters of a directory name, for example the “Documents and Settings” is a directory that contains more than 8 characters, instead of typing them all and messing with it, we can use the ‘~’ operator, so that it will automatically recognizes the path and performs the operation mentioned.

      C:\>cd C:\DOCUME~1\CYB3RC~1\LOCALS~1\Temp