467,146 Members | 1,047 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

Perl output redirection and gnu less problem

This is a small perl script I wrote to check mirror lists (files filled with one URL per line). It prints "[FAIL] http://..." when an URL can't be retrieved and just prints the url when everything goes fine. The code is pretty straightforward and it works well until I am trying to redirect its output.

There is one thing I can't figure out. As far as I know the program called 'less' prints its input on the screen providing a nice interface for examining the contents of another program's output.

less works fine in situations like:
Expand|Select|Wrap|Line Numbers
  1. perl -e 'print "test"' | less
  2. ls | less
  3. cat /etc/passwd | less
The problem is that using my script 'less' only gets the lines sent to STDERR.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #
  3. # Usage: ./linkchk.pl filename_containing_urls
  4. # or cat file | ./linkchk.pl
  6. use LWP;
  7. $ua=LWP::UserAgent->new;
  8. $ua->timeout(3);
  9. $req=HTTP::Request->new;
  10. $req->method("HEAD");
  12. # create and urllist file
  13. # try ./linkchk.pl urllist | less
  14. print STDOUT "Why can't ./linkchk.pl urllist|less see this?\n";
  16. while (<>)
  17. {
  18.         chomp($line=$_);
  19.         $req->uri($line);
  20.         $res=$ua->request($req);
  21.         if ($res->is_success)
  22.         {
  23.           print STDOUT "$line\n";
  24.         }
  25.         else
  26.         {
  27.           print STDERR "[FAIL] $line\n";
  28.         }
  29. }
any clues?

(Fedora9, perl 5.10.0)
Aug 10 '08 #1
  • viewed: 1678
1 Reply
Expert 512MB
It appears that you are not using 'less' in the proper manner. This maybe be the reason that it is printing to STDERR. What is the error message that it is printing?

Unless, I am completely misunderstanding what you are doing with 'less'.

Aug 17 '08 #2

Post your reply

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

Similar topics

3 posts views Thread by Pat Deegan | last post: by
15 posts views Thread by Taki Jeden | last post: by
7 posts views Thread by Piotr Turkowski | last post: by
reply views Thread by Kirt Loki Dankmyer | last post: by
7 posts views Thread by fatalserpent | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.