in reply to Re: Problem dup'ing STDOUT
in thread Problem dup'ing STDOUT

Perhaps, but when I read in the Camel Book about exec, it indicates that "The exec function terminates teh current program and executes an external command and never returns!!! Use system instead of exec." I do not want the program to terminate, I need to retain control to do other things. Perhaps my example wasn't as explicit as it should have been.


"Ex libris un peut de tout"

Replies are listed 'Best First'.
Re: Re: Re: Problem dup'ing STDOUT
by holo (Monk) on Nov 26, 2003 at 16:58 UTC
    Does exactly the same thing as "exec LIST", except that a fork is done first

    From system documentation. It is equivalent to a fork/exec, just more efficient.

    The point is that qx// returns the output as a scalar or array but does not explictly print anything to STDOUT (as it used to be in the old days in null context apparently).

Re: Re: Re: Problem dup'ing STDOUT
by Joost (Canon) on Nov 26, 2003 at 17:40 UTC
    Use system instead of exec.
    Like it says; just use system instead of exec (or qr//) and you'll be allright.

    Joost.

    -- #!/usr/bin/perl -w use strict;$;= ";Jtunsitr pa;ngo;t1h\$e;r. )p.e(r;ls ;h;a;c.k^e;rs ";$_=$;;do{$..=chop}while(chop);$_=$;;eval$.;
      Not quite. According to my copy of the Camel Book, under system() it says:
      To capture the output from a command, use backticks or qx//."

      Which is what I had been doing.


      "Ex libris un peut de tout"
        No, you dumped the output away:

        From perlop / qx:

        The collected standard output of the command is returned; standard error is unaffected. In scalar context, it comes back as a single (potentially multi-line) string, or undef if the command failed. In list context, returns a list of lines (however you've defined lines with $/ or $INPUT_RECORD_SEPARATOR), or an empty list if the command failed.
        That means the output of qx!command! will not be send to STDOUT, but returned from the qx call; you cannot capture it from outside the perl program executing qx!command!. You need system("command") which will let all output through to STDOUT (and STDERR) so you can capture it later.

        You COULD also do print qx!command! but I don't really see the point :-)

        Joost.

        -- #!/usr/bin/perl -w use strict;$;= ";Jtunsitr pa;ngo;t1h\$e;r. )p.e(r;ls ;h;a;c.k^e;rs ";$_=$;;do{$..=chop}while(chop);$_=$;;eval$.;