in reply to Re: system call vs. back quotes
in thread system call vs. back quotes

Perhaps I'm missing something obvious here. Could you explain to me how this:
system ("/bin/tar", "czf", "/tmp/stuff.tar.gz", "/stuff");

is different from this:
`/bin/tar czf /tmp/stuff.tar.gz /stuff`

Is there some inherent advantage to the system call other than those listed by Chmrr above?

Thanks for the clarification.

Vavoom

Replies are listed 'Best First'.
Re: Re: Re: system call vs. back quotes
by ton (Friar) on Jan 25, 2002 at 05:34 UTC
    The Perl Cookbook claims (in the Discussion 16.1) that there is overhead associated with the backticks that does not exist with the system call. I imagine perl does the openpipe/fork combination to get the STDOUT from the backticks; if you don't need the output (as in the tar example above), it is thus more efficient to use system.

    -Ton
    -----
    Be bloody, bold, and resolute; laugh to scorn
    The power of man...

Re: Re: Re: system call vs. back quotes
by impossiblerobot (Deacon) on Jan 25, 2002 at 08:52 UTC
    The 'system' call treats its first argument as the command to run and the remaining arguments as arguments to that command. Bypassing the shell means that even if the other arguments contained pipe/redirect characters or other commands, those redirects, commands, etc. will not processed. That helps to eliminate a lot of security problems that can be caused by tainted data.

    (Of course, that's not to say that you shouldn't run in taint mode and untaint your data anyway.)

    Impossible Robot