Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Unable to flush stdout: Invalid argument

by ww (Archbishop)
on Jan 22, 2017 at 13:45 UTC ( #1180119=note: print w/replies, xml ) Need Help??


in reply to Unable to flush stdout: Invalid argument

We may be able to help... if you show us your ( SSCCE ) code.


 $anecdote ne $data

Replies are listed 'Best First'.
Re^2: Unable to flush stdout: Invalid argument
by bakiperl (Acolyte) on Jan 22, 2017 at 15:47 UTC

    The scripts are pretty big and I checked that every filehandle is being closed but at the top of the scripts I have the following code. Could that be the reason?

    BEGIN { use CGI::Carp qw(carpout); open(LOG, ">>/Logs/Report.log") && carpout(\*LOG); carpout('LOG'); }
      "The scripts are pretty big ..."

      That makes no sense in response to an implicit suggestion to read: The SSCCE: Short, Self-Contained, Correct (Compilable) Example.

      From your OP:

      "Unable to flush stdout: Invalid argument?"

      Find out what generates that message and track back from there.

      You might also consider modifying that code such that it produces a more useful message. Something like:

      • What argument does it refer to?
      • What line did it occur on?
      • What other relevant information is available?
      "open(LOG, ">>/Logs/Report.log") ..."

      Avoid using global package variables: that leads to action-at-a-distance and bugs that are hard to track down. Instead, use lexical variables in the smallest scope possible.

      Use meaningful names. Using common, globally scoped, package variables (e.g. FILE, LOG, IN, OUT), just exacerbates the problem and makes your debugging task all the more difficult.

      Read the open documentation, then rewrite that code more like this:

      open my $report_log_fh, '>>', $logfilename ...

      Not checking for I/O errors is also a problem. Either write your own; something like:

      ... or die "Can't open '$logfilename' for appending: $!";

      Or save yourself all that effort and let Perl do it for you with the autodie pragma.

      "carpout('LOG');"

      Read the CGI::Carp documentation:

      "The carpout() function requires one argument, a reference to an open filehandle for writing errors."

      Your argument, 'LOG', is a literal string.

      Does your script start with these two lines?

      use strict; use warnings;

      If not, add them. They may well highlight all sorts of problems you weren't aware of. Like autodie, strict and warnings are two more examples of Perl doing the work for you, if you just ask.

      Finally, kindly read "How do I post a question effectively?" and follow the instructions therein. We're happy to help but we're not psychic: if you provide the appropriate information, you'll usually get a quick response, that actually answers your question, rather than guesswork and requests for more information.

      — Ken

        I personally have not been able to reproduce the error message and that's why I was not able to narrow down the problem. The error is occasionally produced when the application is used by web users. Unfortunately the CGI::Carp does not show the line where the error is occurring.

        The following two lines are part of the script.

        use strict; use warning;

        May be I need to try the autodie module and see if it helps.

        Sorry for being vague with my statement: "The scripts are pretty big ..."

      > The scripts are pretty big

      Maybe try using a binary search debugging strategy?

      From http://stackoverflow.com/questions/843909/debugging-and-binary-search

      If you don't know which line in a 100 line program is buggy, you'd try to run the first 50 lines and skip the rest. If the problem show up, you'd know this first segment contains the bug. You'd next try to split this and run the first 25 lines and see if the problem is there and so on until you have figured out a short enough piece to look at

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1180119]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-07-17 19:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (377 votes). Check out past polls.

    Notices?