Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
3_4_format.doc
Скачиваний:
1
Добавлен:
01.05.2025
Размер:
94 Кб
Скачать
☆

6 Requirements for the content of the protocol

  1. Name of laboratory work.

  2. Objective.

  3. The results of the assignment.

  4. Brief description of the work done.

  5. Conclusions of the work done.

  6. Date, signature of the student visa is a teacher.

Lab № 4

Readdress of input/output, conveyor

1 Purpose of

1.1 Examine input / output streams in OS UNIX.

1.2 Get familiar with standard input / output streams.

1.3 Implement diversion flows.

2 Key provisions

2.1 Standard streams

Standard input / output device provides some basic facilities of input-output. These are the three standard streams: input, output and error. Under the agreement, the standard output stream contains all the "normal" output of the program, while the standard error consists of error messages. By default the standard input program is a keyboard, and standard output and error are sent to the screen.

At the time of receipt of the standard input stream (Fig. 6) or divert a file (Fig. 7), the kernel assigns each file number, or tag:

  • standard input (stdin) receives a file descriptor 0 (associated with the file from the process reads the data);

  • standard output (stdout) receives a file descriptor 1 (associated with the file where the process of recording their answers);

  • standard error (stder) receives a file descriptor 2 (linked to the tether, where the process sends error messages).

Figure 6 - Opening of the standard I / O streams without forwarding commands

2.2 Pereadrssatsiya standard input / output

The main advantage of standard I / O is the ability to redirect input or output from the terminal to a file (Fig. 7).

Figure 7 - Standard output redirected to a file

Despite the fact that the standard I / O is a key element of UNIX, the syntax to redirect depends on the type of interpreter shell (Table 19).

Table 19 - Common ways to redirect standard input-output

Action

csh

sh

1

2

3

Redirect stdout to file

Redirect stderr to file

Redirect stdout and stderr to file

Reading stdin from file

program> file

program> & file

program <file

program> file

program 2> file

program> file 2> & 1

program <file

Redirect stdout to end of file

Redirect stderr to the end of file

Redirect stdout and stderr to the end of file

program>> file

program>> & file

program>> file

program 2 >> file

program>> file 2> & 1

Reading stdin from the keyboard until will be entered a symbol c

program>> c

program>> c

Send stdout to channel

Send stdout and stderr to a channel

program □

program 2

program □ & program 2

Consider a few examples of redirection of standard input-output:

  1. To send a file by e-mail user joan, using the operator <filename that tells the interpreter shell, that the standard input program mail instead of a keyboard, connect the file:

% Mail joan <myfile

  1. To send output commands in a file rather than print them on the terminal must be:

% Cat filel file2> file 3

The most common form of redirection in UNIX is a channel (denoted by the operator | (vertical bar)).

For example, to send a correspondent joan files file1 and file2 in one e-mail message, you must enter the following:

% cfn file1 file2 | mail joan

Secure forwarding of I / O

Setting variable noclobber prevent accidental destruction of data file with redirection of standard output. Consider the following scenario:

% Command> output_file

This line command deletes the old output file and creates a new one. If you or falsity enter the file name, or forgot that the file already exists and contains important data, or going to type>> instead of>, then, unfortunately, your old data will be destroyed.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]