Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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

        - 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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2017-05-30 09:23 GMT
Find Nodes?
    Voting Booth?