1 00:00:00,000 --> 00:00:04,300 [Intro Music] 2 00:00:04,350 --> 00:00:06,780 We have just tried to send the data 3 00:00:06,780 --> 00:00:09,360 from STDOUT and STDERR to 4 00:00:09,390 --> 00:00:11,370 different files; and it was 5 00:00:11,370 --> 00:00:13,110 successful. We have written 6 00:00:13,110 --> 00:00:14,550 different streams to different 7 00:00:14,550 --> 00:00:17,040 files. And actually we have tried 8 00:00:17,070 --> 00:00:19,440 this part. There were two different 9 00:00:19,470 --> 00:00:21,840 data streams STDOUT and STDERR, 10 00:00:21,840 --> 00:00:24,630 and two different files. But what 11 00:00:24,660 --> 00:00:27,300 if we want to send the data from 12 00:00:27,330 --> 00:00:30,540 STDOUT data stream to STDIN of 13 00:00:30,600 --> 00:00:34,740 other process. Let's try it using the 14 00:00:34,740 --> 00:00:36,720 same approach as we used in 15 00:00:36,720 --> 00:00:38,640 previous lectures. Let's go to the 16 00:00:38,640 --> 00:00:40,830 terminal and let's suppose that we 17 00:00:40,830 --> 00:00:43,560 want to redirect STDOUT of 'ls' 18 00:00:43,560 --> 00:00:46,560 command to STDIN of 'cat' command. 19 00:00:47,310 --> 00:00:49,080 Let's try approach that we have 20 00:00:49,080 --> 00:00:52,350 used with files, 'ls', then comes 21 00:00:52,380 --> 00:00:54,390 greater than, '>' operator that will 22 00:00:54,420 --> 00:00:57,450 redirect actually STDOUT of 'ls' 23 00:00:57,450 --> 00:00:59,970 command; and let's here write 'cat' 24 00:00:59,970 --> 00:01:03,030 command, and let's press Enter, and I 25 00:01:03,030 --> 00:01:06,269 see actually nothing. I could try 26 00:01:06,480 --> 00:01:09,630 here add '1' because '1' is ID of 27 00:01:09,630 --> 00:01:12,360 STDOUT, and press Enter, and again 28 00:01:12,360 --> 00:01:14,730 nothing. And that means that with 29 00:01:14,730 --> 00:01:17,070 this '>' operator, you are not 30 00:01:17,100 --> 00:01:20,520 able to redirect data from STDOUT 31 00:01:20,550 --> 00:01:24,690 or STDERR to STDIN of other process. 32 00:01:25,140 --> 00:01:26,490 That's why here we see nothing. 33 00:01:27,420 --> 00:01:29,250 If you want to do so, you need to 34 00:01:29,250 --> 00:01:32,100 use other operator called pipe, '|', and 35 00:01:32,100 --> 00:01:34,710 approach that is called Piping. With 36 00:01:34,710 --> 00:01:37,996 piping you could send data from STDOUT 37 00:01:37,996 --> 00:01:40,770 of one process to STDIN of 38 00:01:40,800 --> 00:01:43,410 other process. Next, you are also 39 00:01:43,410 --> 00:01:46,020 able to send STDOUT data flow from 40 00:01:46,020 --> 00:01:48,450 this process to another STDIN 41 00:01:48,480 --> 00:01:51,270 of other process, and so on. You could 42 00:01:51,300 --> 00:01:53,550 pipe different processes one after 43 00:01:53,550 --> 00:01:57,110 previous. But please notice that STDERR 44 00:01:57,110 --> 00:02:00,360 data stream is not piped, and 45 00:02:00,360 --> 00:02:02,370 you are able to write it to the 46 00:02:02,370 --> 00:02:04,290 file same as we did in previous 47 00:02:04,290 --> 00:02:07,140 examples, or you could still bring 48 00:02:07,140 --> 00:02:09,030 it to the terminal, that is actually 49 00:02:09,030 --> 00:02:11,880 a default action. All right, let's 50 00:02:11,880 --> 00:02:13,919 try to use piping here in this 51 00:02:13,919 --> 00:02:16,740 example with 'ls' and 'cat' processes; 52 00:02:17,160 --> 00:02:20,520 and for that I'll type 'ls', then pipe, '|' 53 00:02:20,670 --> 00:02:22,920 this vertical line, and here will be 54 00:02:22,920 --> 00:02:26,460 'cat' like so. Press Enter, and now I 55 00:02:26,460 --> 00:02:28,380 see a list of files and folders. 56 00:02:28,860 --> 00:02:31,290 And that means that now STDOUT 57 00:02:31,440 --> 00:02:35,370 from 'ls' process was sent to STDIN 58 00:02:35,490 --> 00:02:39,780 of 'cat' process. Alright, but let me 59 00:02:39,780 --> 00:02:41,820 demonstrate to you that pipe does not 60 00:02:41,850 --> 00:02:44,310 send STDERR data stream. For 61 00:02:44,310 --> 00:02:46,590 that I could use here 'cat' command 62 00:02:46,620 --> 00:02:50,040 with some missing file, 'missing-file 63 00:02:50,160 --> 00:02:52,350 .txt', like so; and then let's 64 00:02:52,350 --> 00:02:54,270 suppose that I want to pipe result 65 00:02:54,270 --> 00:02:56,340 of this command to another 'cat' 66 00:02:56,340 --> 00:02:59,370 process, press Enter, and I see 67 00:02:59,400 --> 00:03:00,960 error directly here in the 68 00:03:00,960 --> 00:03:04,079 terminal. And that means that STDERR 69 00:03:04,079 --> 00:03:06,570 data stream was not sent to 70 00:03:06,630 --> 00:03:09,480 another process. Alright, that's 71 00:03:09,480 --> 00:03:11,160 how you could pipe different 72 00:03:11,160 --> 00:03:13,320 processes together. For example, let 73 00:03:13,320 --> 00:03:16,830 me pipe another process 'echo'; and by 74 00:03:16,830 --> 00:03:18,300 default this command will simply 75 00:03:18,300 --> 00:03:20,610 print some text to the terminal and 76 00:03:20,610 --> 00:03:22,410 this text will be supplied here as 77 00:03:22,410 --> 00:03:24,630 argument. Let's type "Hello World". 78 00:03:25,440 --> 00:03:27,630 And if I press Enter now I see 79 00:03:27,690 --> 00:03:30,630 output from STDOUT data stream, and 80 00:03:30,630 --> 00:03:32,550 it prints "Hello world". Now let's 81 00:03:32,550 --> 00:03:33,960 suppose that I want to send the 82 00:03:33,960 --> 00:03:37,770 result of this operation to another 83 00:03:37,920 --> 00:03:40,050 command; and let's use here again 84 00:03:40,050 --> 00:03:42,450 'cat'; and let's suppose that I want 85 00:03:42,450 --> 00:03:45,300 to write result of 'cat' operation 86 00:03:45,330 --> 00:03:48,540 from STDOUT to file; and here I 87 00:03:48,540 --> 00:03:50,190 could use the following syntax 88 00:03:50,490 --> 00:03:52,740 '>'; and here will 89 00:03:52,740 --> 00:03:55,989 be 'hello.txt'. Again here following 90 00:03:55,989 --> 00:03:58,830 will happen, STDOUT data stream of 91 00:03:58,860 --> 00:04:02,559 this process will send data to STDIN 92 00:04:02,559 --> 00:04:06,270 of 'cat' process, and STDOUT of 93 00:04:06,270 --> 00:04:09,570 'cat' process will be stored in the 94 00:04:09,570 --> 00:04:12,750 file hello.txt. If this file is 95 00:04:12,750 --> 00:04:14,190 absent, it will be created. 96 00:04:14,640 --> 00:04:17,610 Alright, let's try that. Enter. I see 97 00:04:17,610 --> 00:04:19,920 nothing here in the terminal. But 98 00:04:19,950 --> 00:04:21,990 if I list the contents of file 99 00:04:22,019 --> 00:04:24,540 hello.txt, I see "Hello world". 100 00:04:25,290 --> 00:04:27,029 That's how it works, and that's how 101 00:04:27,029 --> 00:04:29,880 you're able to combine pipe, '|' operator 102 00:04:30,030 --> 00:04:32,190 and redirect, '>' operator. Please note 103 00:04:32,190 --> 00:04:34,320 again that redirect, '>' operator will 104 00:04:34,320 --> 00:04:36,450 write contents only to file, it is 105 00:04:36,450 --> 00:04:39,306 not capable of sending data to STDIN 106 00:04:39,306 --> 00:04:41,730 of other processes. For that you 107 00:04:41,730 --> 00:04:44,460 need to use pipe, '|' operator. Alright, 108 00:04:44,610 --> 00:04:45,840 that's all for this lecture and 109 00:04:45,840 --> 00:04:47,520 next let me summarize what we have 110 00:04:47,520 --> 00:04:48,930 discussed over the course of the 111 00:04:48,930 --> 00:04:51,400 previous lectures. I'll see you next. Bye-Bye. 112 00:04:51,400 --> 00:04:54,300 [no audio]