in reply to Re: Help: STDOUT flaking out?
in thread Help: STDOUT flaking out?

This still is not working. The file "tabfile" is a shell script that created the file "FTPData.20010517.111754". I am trying to capture that echoed output and redirect it into a file. Might there be a better way to do this with a pipe or some other mechanism? Please advise :)
RESULT: $ ftp_flow.pl logfile = /tmp/ftp_flow.111753410117.log errfile = /tmp/ftp_flow.111753410117.err FTPData.20010517.111754 $ cat /tmp/ftp_flow.111753410117.log $ (the file is empty... it should contain "FTPData.20010517.111754" as the 1st line) CODE: # send output to file @args2 = ("$tabfile"); local(*LOGFILE); open (LOGFILE, ">$logfile") || die "could not open log\n"; select(LOGFILE); unless (system(@args2) == 0) { print STDERR "system(@args2) failed: $? $!\n"; return; } close(LOGFILE); print "foo1\n"; exit (0);

Replies are listed 'Best First'.
Re: Re: Re: Help: STDOUT flaking out?
by suaveant (Parson) on May 17, 2001 at 19:34 UTC
    you probably really want to just use backticks...
    # send output to file ###either open (LOGFILE, ">$logfile") || die "could not open log\n"; print LOGFILE `$tabfile`; if($?) { print STDERR "$tabfile failed: $?\n"; return; } close(LOGFILE); ##or `$tabfile > $logfile`; if($?) { print STDERR "$tabfile failed: $?\n"; return; } ## end or print "foo1\n"; exit (0);

                    - Ant
      Thank you. I removed the code which was screwing up STDOUT. It all works now. :)
Re: Re: Re: Help: STDOUT flaking out?
by myocom (Deacon) on May 17, 2001 at 19:32 UTC

    You need to select(STDOUT); after your close(LOGFILE);. Right now, you're still printing to a closed filehandle...

Re: *Problem Solved* Help: STDOUT flaking out?
by P0w3rK!d (Pilgrim) on May 17, 2001 at 19:34 UTC
    This works now: Thank you :)
    # send output to file @args2 = ("$tabfile"); open (LOGFILE, ">$logfile") || die "could not open log\n"; unless (system(@args2) == 0) { print STDERR "system(@args2) failed: $? $!\n"; return; } select(LOGFILE); close(LOGFILE);
      In reference to the previous postings: After I cat the log file I create, it shows that not only the 1st line which was grabbed from the $tabfile output, but also the output from:
      print "foo1\n";
      and
      print "GOT THIS: $lines\n";
      RESULT: $ ftp_flow.pl logfile = /tmp/ftp_flow.12547410117.log errfile = /tmp/ftp_flow.12547410117.err $ cat /tmp/ftp_flow.12547410117.log FTPData.20010517.120547 foo1 GOT THIS: FTPData.20010517.120547 $
      How do I set STDOUT back to normal?
      # send output to file @args2 = ("$tabfile"); open (STDOUT, ">$logfile") || die "could not open log\n"; unless (system(@args2) == 0) { print STDERR "system(@args2) failed: $? $!\n"; return; } select(STDOUT); close(STDOUT); print "foo1\n"; # read the file to obtain the file tabdata created local(*LOGFILE); open (LOGFILE, $logfile) || die "Couldn't open: $!"; $lines=<LOGFILE>; #get line 1 from the file close(LOGFILE); print "GOT THIS: $lines\n"; exit(0);