in reply to QuickPerl: a step up from -e

How about doing a fork, redirecting STDERR in the child to a pipe who's other end is open in the parent, and then execing "perl quick_run.perl"? I don't know whether that will work or not but it's likely. Update: That is, of course, instead of doing the system call.

HTH

bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.

Replies are listed 'Best First'.
Re: QuickPerl: a step up from -e
by Abigail (Deacon) on Jul 05, 2001 at 03:47 UTC
    How about doing a fork ... That is, of course, instead of doing the system call.

    How do you think system is actually implemented? Under UNIX, system *is* doing a fork and an exec. Under Windows, there's no native fork, but the principle remains the same: what you are replacing system with is just what system is already doing.

    -- Abigail

      Yes, I'm aware that's how system is implemented. My point was more of doing the STDERR redirect after the fork but before the exec so that it wasn't changed for the parent. It seems, however, that John is using windows which doesn't support fork properly, so it's kind of pointless. :-) So I guess you would just have to redirect STDERR, do the system call, and then restore STDERR. *shrug*

      Update: See my other reply.

      bbfu
      Seasons don't fear The Reaper.
      Nor do the wind, the sun, and the rain.
      We can be like they are.

Re: (bbfu) Re: QuickPerl: a step up from -e
by John M. Dlugosz (Monsignor) on Jul 05, 2001 at 03:37 UTC
    Fork is a little odd in Windows, and doesn't really start a new process. So what will the exec do?!

    I think maybe redirect STDERR, and then run Perl feeding it a bootup script which redirects it again before running the real script, but I think that won't work because perl.exe will see and respect the change (again), too.

      So what will the exec do?!

      I have no idea. :-p

      Well, system is basically the same thing as fork/exec and my point was basically to do the STDERR redirect between the fork and the exec so that it wouldn't be (temporarily) redirected in the parent. I suppose that it's not really that big of a deal so you might as well just do:

      # # Note: UNTESTED!!! # sub do_run { # write file... local *OLDERR, *NEWERR; open(OLDERR, ">& STDERR") or die "Can't dup STDERR: $!"; pipe(NEWERR, STDERR) or die "Can't pipe: $!"; system "perl quick_run.perl"; open(STDERR, ">& OLDERR") or die "Can't restore STDERR: $!"; my @error_lines = <NEWERR>; return @error_lines; }

      bbfu
      Seasons don't fear The Reaper.
      Nor do the wind, the sun, and the rain.
      We can be like they are.

        I see your point on why it can be useful to separate the two, to do something in between. exec in ActiveState's port sais it will emulate it by starting a new process and then waiting for it to finish, then exiting with the same code itself. So it leaves the old program in memory!