Hello Monks,

Is it possible to capture STDOUT (*And STDERR if possible) when using the Proc::Background Module?

I did a good bit of searching for this and the only thing I really found that might have made sense was to do
something like this below, but I get errors when I do. The stuff I found from some of the searches I did was the part
at the end of the code where I'm opening a FILEHANDLE... But I get errors, when I do that.

       *F.Y.I.: This is part of a Gtk2 GUI I'm writing, and the code is from inside a function that executes when you click a button...
--------------------------------------------------------------------- my $proc = Proc::Background->new($bg_script, "$ARG1", "$ARG2"); my $PID = $proc->pid; # Get the PID my $start_time = $proc->start_time; # Get the Start Time # Check if the Job is still alive... 1==YES, 0==NO my $alive = $proc->alive; # While $alive is NOT '0', the process is still running while($alive ne 0) { # Check again if it's still running... $alive = $proc->alive; # This while loop will force Perl::Gtk2 to continue # processing GUI Events while BG process continues executing... while (Gtk2->events_pending) { Gtk2->main_iteration; } Gtk2::Gdk->flush; # Sleep for 1000 milliseconds usleep(1000); } # Capture the Exit Status from Background Script my $socket_RETCODE = $proc->wait; # Divide RETCODE by 256 to get actual RETCODE $socket_RETCODE /= 256; ########################################################### ### Attempt to Capture the OUTPUT: open( PROC, "$proc" ) or die "Can't read from $proc: $!\n"; my $output = print PROC; ########################################################### ---------------------------------------------------------------------
OUTPUT ERRORS FROM 'open()' COMMAND:
*** unhandled exception in callback:
*** Can't read from Proc::Background=HASH(0x8a2a2ac): No such file or directory


So I'm assuming from the errors above that you'd have to do that 'open()' command while the Background Job is still running..??

And if I move the open() cmd to just before the while loop and then put the assignment statement for $output variable inside the
while loop It will just hang at that point and I am forced to have to Ctrl+C to kill it...

I figure this is somehow possible I just can't figure it out...
Any hints/suggestions would be GREATLY appreciated..!!


EDIT: After reading some more on the open() command for this purpose I'm realizing they were using the open command to START
the job and not just to capture the output...

Thanks in Advance,
Matt


In reply to Capturing STDOUT and/or STDERR from Proc::Background by mmartin

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.