Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Inline: where did the output go?

by cdarke (Prior)
on Jun 12, 2007 at 13:39 UTC ( #620719=note: print w/replies, xml ) Need Help??


in reply to Inline: where did the output go?

My first thought was buffer flushing (fflush(stdout)) but I cannot see how a redirection to a file would affect that. In theory there should be no difference between writing to a screen and a file, unless the code calls something like istty(), or checks for screen attributes.
Another possibility is that the shell you are running from is crashing, and never flushes the file buffer, but that is unlikely
I recall some issues using printf from XS when I had to use the PerlIO layers, for example:
PerlIO * debug = PerlIO_open ("debug.txt", "a"); PerlIO_printf(debug, "\nEntry, File: %s\n", szName);
But I have no idea if you need this with your inline code. Can I suggest that you show a small sample of code?
A run of strace or truss (with -f option), or ltrace if you have it, might clarify what is going on.

Replies are listed 'Best First'.
Re^2: Inline: where did the output go?
by andye (Curate) on Jun 12, 2007 at 14:25 UTC
    Hi cdarke,

    I'm trying to work up a minimal example to show the problem - the issue I've got now is that when I make the example very minimal, the problem goes away. :)

    You may be right that it's a buffering problem though: I've written an example script which prints a line from Perl, then a line from C, then a line from Perl. On my Mac the lines appear in the file in the expected way, but on the Linux machine where I've originally found the problem, they appear in this order:
    1 Perl
    3 Perl
    2 C
    (should be 1 Perl, 2 C, 3 Perl)

    and putting a fflush(stdout) in the right place solves that problem...

    ...ok, so let's try doing that in the real script... success! Hooray!

    Triple++ (if I could) to cdarke, and many thanks.

    Best wishes, andye

      Hummm. Not sure I deserve that. The buffer should be flushed on exit from the program, regardless of whether it goes to the screen or a file.
        Ah, but (and I should maybe have mentioned this before) the process runs for a long time, i.e. a couple of days.

        It's a long batch-processing job. (That's why I'm using Pdlpp to code part of it, because I need to get up to C speed otherwise it takes forever).

        So,
        - need to get output during the program run, as the point of the output is to show progress.
        - when I've been testing it to see if anything was showing up in the output file, I've been waiting a while and when nothing appeared I've been killing the process.

        Best wishes, andye

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://620719]
help
Chatterbox?
[Discipulus]: we too; using opsview alarms
[marto]: the key word: outsourcing ;)
[Corion]: marto: Yeah, feels like that ;) You could set up the cronjob that auto-creates tickets :-))
[marto]: the ticketing system does not accept calls via email, nor has it a working API. It's tied into Active Directory for authentication and the Solaris boxes aren't on that domain
[Corion]: The one thing I haven't figured out a solution to is how to get an edge-trigger instead of sending an email every 5 minutes if the usage is above 90%. I want one mail when it goes over 90% but no more emails as long as it stays between 90% and 95%.
[Corion]: marto: Clever! ;)
[Corion]: You can only reach me by pager
[Corion]: Maybe the solution would be to launch a cron job every minute that takes two measurements a minute apart and sends a mail if the usage is below on the first and above threshold on the last measurement
[marto]: that's essentially it :)
[marto]: I think the long term solution would be to have sysadmins that do their job, so I don't have to do everything :P

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2017-01-24 10:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (203 votes). Check out past polls.