in reply to Exec'ing and output

It seems to me you might not really want to fork and exec... you might want to just fork. Then you can do anything you want in the child. From there, use IPC::Open3 or qx// (or open a pipe) with some redirection to get at both the stdout/stderr of the process. Use whatever method you want to hand the output back to the parent.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^2: Exec'ing and output
by Anonymous Monk on Oct 21, 2005 at 21:16 UTC
    Well, the only reason I want to exec is because what I want to do in the child is contained in (several) separate scripts, which the daemon won't 'know' about in advance.

    Also, I can't let the script just sit and wait for one script to finish before moving on to the next, as I may need to exec several scripts one after another, independently, and they could take some time to complete. So system()'ing them is out.

    This leads to another problem.. Is there any way that you can distinguish which process/scripts last wrote to STDOUT or STDERR if I reopen those filehandles to a temporary filehandle or a scalar as an above monk posted?

    Ideally, what I'd like to do is tell the children that are exec()'ing to call my logging function whenever their scripts print to STDOUT or STDERR. Is this even possible? I have a pretty specific logging format I need to conform to, and I'd like to be able to just call a function with the content of a print statement, and allow that function to handle formatting.

    Thanks again for all of your help.

      This leads to another problem.. Is there any way that you can distinguish which process/scripts last wrote to STDOUT or STDERR if I reopen those filehandles to a temporary filehandle or a scalar as an above monk posted?

      You can reopen them to a new filehandle for each invocation and keep all the active filehandles. Use select to see which have data ready to be read. (IO::Select might be an easier interface to deal with.)

      -sauoq
      "My two cents aren't worth a dime.";