473,395 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Perl output redirection and gnu less problem

1
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.


linkchk.pl
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #
  3. # Usage: ./linkchk.pl filename_containing_urls
  4. # or cat file | ./linkchk.pl
  5.  
  6. use LWP;
  7. $ua=LWP::UserAgent->new;
  8. $ua->timeout(3);
  9. $req=HTTP::Request->new;
  10. $req->method("HEAD");
  11.  
  12. # create and urllist file
  13. # try ./linkchk.pl urllist | less
  14. print STDOUT "Why can't ./linkchk.pl urllist|less see this?\n";
  15.  
  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. }
  30.  
any clues?

(Fedora9, perl 5.10.0)
Aug 10 '08 #1
1 1889
eWish
971 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'.

--Kevin
Aug 17 '08 #2

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

Similar topics

3
by: Pat Deegan | last post by:
Greetings, I've been having issues while debugging programs. The problems only appear when using the '-d' switch and I get the impression it has to do with UTF8 and regex matching but I don't...
15
by: Taki Jeden | last post by:
Hello everybody Does anybody know why w3c validator can not get pages that use 404 htaccess redirection? I set up two web sites so that clients request non-existent urls, but htaccess redirects...
7
by: Piotr Turkowski | last post by:
Hi! I've got some code in Perl and I have to have it in C, but my knowlege of Perl is < 0 :-(, so I need your help. here's the code. Thanks in advance. decrypt.pl #!/usr/local/bin/perl...
4
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
3
by: Liren Zhao | last post by:
I use some "Console.WriteLine(some strings here)" to display some debug information in my winform program. How can I get the information in my programe or same them in a text file ?
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
2
by: Marty Meyers | last post by:
I have the following line in a php file: $msg= exec("perl $scriptPath/insert.pl $d $u $t 2>&1", $returnVal); Can someone explain the "2>&1" argument? Second problem, this same line of code...
7
by: fatalserpent | last post by:
Here is the basic code (yes, I know its tiny). x = print "x =", x for m in x: print m I want to modify this so it will output to a file called 1. What I want is to have that file direct its...
2
by: prajil | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.