By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,948 Members | 1,651 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,948 IT Pros & Developers. It's quick & easy.

using perl to override output redirection

P: 2
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.
Oct 17 '07 #1
Share this Question
Share on Google+
2 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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
Oct 17 '07 #2

P: 2
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
>
-------------
Oct 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.