Perl output streams: STDERR, STDOUT,

I know the output streams STDOUT and STDERR. Whenever you type in STDOUT, in a unix shell, you can redirect the output as follows:

deviolog@home:~$ perl test_script.pl > output.txt

or

deviolog@home:~$ perl test_script.pl 1> output.txt

When you type in STDERR, it looks the same, but you switch to "channel" (?) Number 2:

deviolog@home:~$ perl test_script.pl 2> output.txt

I can find in output.txt what I was printing while the error output.

My question is: can I somehow access the "channel" number 3? There is something like ...

 print STDX "Hello World!\n";

... which allows redirection, for example the following:

deviolog@home:~$ perl test_script.pl 3> output.txt

ps Subsequence would be about terms for those "channels" ^ _ ^

+4
source share
3 answers

Perl (fd), open, &= . :

open(my $fh, '>&=', 3)

,

$ perl -E'
   open(my $fh, ">&=", 3) or die $!;
   say fileno($fh);
   say $fh "meow";
' 3>output.txt
3

$ cat output.txt
meow
+7

> file 2> file /, , 2, .

Perl STDIN - , 1, STDOUT STDOUT, 2 3 . STDX. , (. open):

open my $fh, ">&", 3; # $fh will correspond to fd 3, for write

open my $fh, ">&=", 3; # $fh will correspond to fd 3, for write

3 ( ), perl:

perl script.pl 3> file

file , , print $fh ....

+1

, , , . * nix Windows stdin, stdout stderr (0, 1, 2). , () .

, , open(), fd 3, ? , , .

Just use open()to open the file you want to write.

0
source

Source: https://habr.com/ru/post/1537118/


All Articles