Presentation is loading. Please wait.

Presentation is loading. Please wait.

More Command Line Options Pipes, Redirection, Standard files Copyright © 2015 Curt Hill.

Similar presentations


Presentation on theme: "More Command Line Options Pipes, Redirection, Standard files Copyright © 2015 Curt Hill."— Presentation transcript:

1 More Command Line Options Pipes, Redirection, Standard files Copyright © 2015 Curt Hill

2 Introduction These are two features pioneered by UNIX and then partially copied in DOS A pipe is a connector of the output of one program to the input of another Redirection is changing the where the input of a program comes from or the output goes to Copyright © 2015 Curt Hillout

3 Redirection The idea of file redirection is an instance of device independence We want our files to be independent of the type of device Redirection mainly applies to the standard input, output and error files Not every command allows redirection, but most of the standard ones do Copyright © 2015 Curt Hill

4 Output Redirection Output redirection use the > preceding the new file Thus the command: copy *.dat *.txt >results.lst –will do the copy as always but the copy output will be in the results.lst file –Copy output is the names of the files copied and a count Copyright © 2015 Curt Hill

5 Other Redirections Somewhat less common, because most DOS commands take no input –They know everything they need from the command line parameters The input redirection character is < followed by the file The error redirection is >> followed by the file Copyright © 2015 Curt Hill

6 Standard Files DOS had several standard file specifications These included lpt1: lpt2: nul: among others These substituted for a normal file name specification Thus: copy xyz.dat lpt1: prints the file Copyright © 2015 Curt Hill

7 Standard Files The files lpt1: lpt2: lpt3: only word if this is an attached file –Not a network printer Thus most of the standard files are not used much any more Only the nul: is of much value –The : may be left out Silencing a copy: copy a*.dat *.txt >nul –does the copy but nothing sent to console Copyright © 2015 Curt Hill

8 Pipes Once we can redirect standard input and output then pipes are easy A pipe is just a temporary file that connects two programs The character is | and should be put between two programs The OS provides a temporary file –The first program places its standard output in the file –The second program reads its standard input from the file –The file is then deleted Copyright © 2015 Curt Hill

9 Example Assume abc and def are both programs abc | def The abc program sends its standard output to an OS supplied temporary file The def program reads it from there This leads us to the concept of a filter Copyright © 2015 Curt Hill

10 Filters Much more common on UNIX than DOS A filter takes some data from standard input It transforms it in some way It writes it to standard output Copyright © 2015 Curt Hill

11 Example A common filter on UNIX was lc –It prefixed each line with the current line number Suppose that program mon produces a lot of output then: mon | lc >mon.out –will prefix line numbers and save in a file Copyright © 2015 Curt Hill

12 Finally Pipes and redirection were very important in the UNIX environment –Especially before the GUI era They were not as important in the DOS world –It was not automatic to write a program to use them –They are still handy Copyright © 2015 Curt Hill


Download ppt "More Command Line Options Pipes, Redirection, Standard files Copyright © 2015 Curt Hill."

Similar presentations


Ads by Google