How to tell if my program is being piped to another (Perl) -


"ls" behaves differently when output being piped:

  > ls ???  bar  foo  > ls ??? | cat  bar  foo  

how know, , how in perl?

in perl, -t file test operator indicates whether filehandle (including stdin) connected terminal.

there -p test operator indicate whether filehandle attached pipe.

$ perl -e 'printf "term:%d, pipe:%d\n", -t stdin, -p stdin' term:1, pipe:0 $ perl -e 'printf "term:%d, pipe:%d\n", -t stdin, -p stdin' < /tmp/foo term:0, pipe:0 $ echo foo | perl -e 'printf "term:%d, pipe:%d\n", -t stdin, -p stdin' term:0, pipe:1 

file test operator documentation @ perldoc -f -x.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -