-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipe_io.PL
44 lines (29 loc) · 1023 Bytes
/
pipe_io.PL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 2020, 4/05, sun, pm 5:10-5:40
# Pipe is the output in prompt from exterior cmd.
# which is different from file in local and streaming in sockets.
# - is a cmd symbol
# | means pipe, the data from the return result of cmd , writting into the program thru pipe
# < > means file handler, also meaning "STDIN" (standard Input),input from prompt
# to read the return result from cmd into pipe in promt
open my $pipe, '-|', $command || die "the file handler can not be opened."
while( <$pipe> ) {
print " the $_ is read out now."
}
# via module
use IO::Pipe;
my $pipe = IO::Pipe -> new;
$pipe -> reader( " $^X -V " ); # $^X means executable program
while( <$pipe> ) {
print " the $_ is read out now."
}
# vise versa, to write the pipe to cmd in prompt
open my $pipe, "| $command" || die "the filehandler can not be opened due to $!";
foreach(1..10) {
print $pipe "count flag $_\n";
}
# module way
use IO::Pipe;
my $pipe = IO::Pipe -> new;
foreach( 1..10 ) {
print $pipe "count flage $_\n";
}