Categories
Scripts Windows Batch

Redirection Operators

05Operators_Redirectional.bat

::this program will demonstrate redirectional operators, following are provided operators
::>  To redirect command output to another file or stream. If file is already present it is overwritten
::> To redirect command output to another file in append mode

@echo off

::To print  list of system users to file named 05Data.txt.
net users > 05Data.txt

::To append the ping output to same file 05Data.txt
ping yahoo.co.in >> 05Data.txt


::To Print the content of file 
echo Content of file 05Data.txt
type 05Data.txt



::To provide input to sort command. Input is list of numbers which is passed from 05Num.txt
echo Content of file 05Num.txt
type 05Num.txt
echo Applying sort command on File data 05Num.txt
sort <05Num.txt





Output

05Data.txt

User accounts for \\LAPTOP-A4OSG6CL

-------------------------------------------------------------------------------
Administrator            DefaultAccount           defaultuser100001        
Guest                    Owner                    WDAGUtilityAccount       
The command completed successfully.


Pinging yahoo.co.in [74.6.136.150] with 32 bytes of data:
Reply from 74.6.136.150: bytes=32 time=292ms TTL=51
Reply from 74.6.136.150: bytes=32 time=212ms TTL=51
Reply from 74.6.136.150: bytes=32 time=681ms TTL=51
Reply from 74.6.136.150: bytes=32 time=400ms TTL=51

Ping statistics for 74.6.136.150:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 212ms, Maximum = 681ms, Average = 396ms

05Num.txt

5
4
3
2
1

Leave a comment

Design a site like this with WordPress.com
Get started