Connecting Tech Pros Worldwide Help | Site Map

using perl to override output redirection

Newbie
 
Join Date: Oct 2007
Posts: 2
#1: Oct 17 '07
Hi,

Could anyone point how can i override output redirection using perl.
i.e.
command > file 2>&1 will redirect both output and error of command to file
I need to print a message to tty even if there is redirection.
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,565
#2: Oct 17 '07

re: using perl to override output redirection


Quote:

Originally Posted by prajil

Hi,

Could anyone point how can i override output redirection using perl.
i.e.
command > file 2>&1 will redirect both output and error of command to file
I need to print a message to tty even if there is redirection.

Well, one way is to use the open() function and open the file / connection. Then, use a print statement to print to the filehandle from the open function.

ie:
Expand|Select|Wrap|Line Numbers
  1. open(TTY, "|<tty connection>");
  2.  
  3. print TTY ("Your info here!\n");
  4.  
Hope that helped.

Regards,

Jeff
Newbie
 
Join Date: Oct 2007
Posts: 2
#3: Oct 18 '07

re: using perl to override output redirection


Quote:

Originally Posted by numberwhun

Well, one way is to use the open() function and open the file / connection. Then, use a print statement to print to the filehandle from the open function.

ie:

Expand|Select|Wrap|Line Numbers
  1. open(TTY, "|<tty connection>");
  2.  
  3. print TTY ("Your info here!\n");
  4.  
Hope that helped.

Regards,

Jeff


Hi Jeff,

Thanks for your reply. But still it is redirecting to the output file.
------------
>./eg.pl
not a tty
>
-----------
>./eg.pl >& file
>
-------------
Reply


Similar Perl bytes