Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2012, 06:45 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 1 Day 20 h 24 m 2 sec
Reputation Power: 581
Odd output from open with pipe

I am using the following code to launch a script and capture the output to a file.
Code:
open($pipe,"$helper_utils/collect_user_metrics.pl $url |") || die("Cannot run collect_user_metrics.pl: ".$!);
open($fh,'>',"$tempoutput/collect_user_metrics.txt");
print $fh while <$pipe>;
close($pipe);
close($fh);

However, when this is executed I get the following output from my script (not in the capture file):

GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01 d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB( 0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4) GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01 d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)GLOB(0xa01d5b4)

If I comment out the above code, this output goes away and if I run the called script from the command line there is no such output, so clearly it is caused by the pipe. What is this and how do I stop it? TIA.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #2  
Old October 29th, 2012, 06:52 PM
G4143 G4143 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 71 G4143 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 39 m 39 sec
Reputation Power: 1
You could try this and see if it works

Code:
print {$fh} while <$pipe>;


Your way is just printing the value of $fh which is GLOB(0xa01d5b4) on your system/exe.

My bad that won't work. Its better if you select the output file before you print to it...Like this.

Code:
#!/usr/bin/perl

use warnings;
use strict;
use feature qw/state/;
use autodie qw/open close/;

print "Enter input filenme->";
chomp(my $ifilename = <STDIN>);

open(my $IFILE, "<", $ifilename);

print "Enter output filename->";
chomp(my $ofilename = <STDIN>);

open(my $OFILE, ">", $ofilename);

select $OFILE;

print  while ( <$IFILE> );#now print sends data to default which is $OFILE

close($IFILE);
close($OFILE);

__END__

Reply With Quote
  #3  
Old October 29th, 2012, 09:20 PM
spacebar208's Avatar
spacebar208 spacebar208 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: spaceBAR Central
Posts: 191 spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 9 h 55 m 30 sec
Reputation Power: 41
Try it like this:
Code:
open( METRICS, ">$tempoutput/collect_user_metrics.txt" );
open( RESULTS, "$helper_utils/collect_user_metrics.pl $url |" )
 or die "Error running($helper_utils/collect_user_metrics.pl $url): $!\n";
while ( <RESULTS> ) {
  print METRICS "$_";
}
close METRICS;
close RESULTS;
Comments on this post
gw1500se agrees!

Reply With Quote
  #4  
Old October 30th, 2012, 07:16 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 1 Day 20 h 24 m 2 sec
Reputation Power: 581
Thanks for the replies. Spacebar208: I opted for your suggestion and that seems to work.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Odd output from open with pipe

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap