Greetings all my fellow monks,

After running this line:

run \@cmd, \$in, \$out, \$err, timeout( 3, exception => 'timeout' );
where cmd is a little program written in C, which mainly does some printf stuff.

I found that when "\n" is added to the the printf statement as printf("hello world\n"); I can get the output ("hello world") through $out without any problem,
but without it the output is always empty. (IMHO, the ``$out'' is also line-buffered as stdout.)

So, my question is, is there any way to get all the output generated by the C program regardless of the ending newline character?

Any help is appreciated.

Update 1: Here's my code.
#!/usr/bin/perl -w use strict; use warnings; use CGI qw/:standard/; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; use IPC::Run qw/run timeout/; if (param('in')) { $in = param('in'); print p("Input: $in\n"); } else { undef $in; } my @cmd = ( "/data2/tmp/a.exc" ); eval { local $| = 1; run \@cmd, \$in, \$out, \$err, timeout( 3, exception => 'timeo +ut' ); }; print "Timed out...\n\n" if $@ =~ /timeout/; print "ERROR: $err\n\n" if $err; chomp($out) && print "Output: $out\n" if $out; print "Expected output: ", param('out') if param('out');

It's slightly edited, removed the lines not related to the problem.

Update 2:

Sorry, I think it's all my fault:

chomp($out) && print "Output: $out\n" if $out;

This is where the problem lies...after removing chomp($out) &&, things back to normal again. Now I don't know what to say or explain....

A letter to NodeReaper:
The connection here was kinda weird on my attempt to send replies to this node.
I could reach the preview page at a good speed, but when I did the real submission, things became very slow, and finally I got a ``content-length: 0'' on my Opera window...
I think that's why you got many empty nodes. It's okay now.


In reply to Get output after running IPC::Run by pid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.