Re: FAQ 8.28 How can I call backticks without shell processing?



Uri Guttman wrote:
"s" == szr <szrRE@xxxxxxxxxxxxxxx> writes:

s> PerlFAQ Server wrote:
s> [...]
>> 8.28: How can I call backticks without shell processing?
s> [...]
>> open( GREP, "-|", 'grep', @opts, $search_string,
>> @filenames ); chomp(@ok = <GREP>);
>> close GREP;

s> Just a little thing I noticed, regarding the use of @opts and
@filenames s> arrays above; unless each element has a leading or
trailing space, they s> will end up smushed together:

s> if, say, @opts contains ('-a', '-b', '--ccc'), when passed to that
s> open() it will end up becoming -a-b--ccc which is probably not
what most s> would want. Putting a join() around both @opts and
@filenames would get s> what most would like (and possibly using a
map { "'$_'" } @filename to s> quote the filenames in case they
contain sapces.)

where did you get that idea? this invokes exec with a list (see
perldoc -f exec. and for proof:

perl -e '@e = qw( a b c ); open( $e, "-|", 'echo', @e ); print <$e>'
a b c

echo printed its args with spaces as expected so it got 3 separate
args and not 'abc' as you claim it would.

Curious, I thought the behavior would be like:
$ perl -e '@e = qw( a b c ); print @e'
which yields 'abc', as I saw that after the first three arguement of the
normal 3 arg open() it appeared to take a list of additional args that
is passes to what ever you opened. I didn't know it separates them like
it does. Good to know.

--
szr


.



Relevant Pages

  • Re: FAQ 8.28 How can I call backticks without shell processing?
    ... s> Uri Guttman wrote: ... >> echo printed its args with spaces as expected so it got 3 separate ... >> args and not 'abc' as you claim it would. ...
    (comp.lang.perl.misc)
  • Re: tr
    ... >> You may need to put single ticks around the tr args, depending on ... >> clashes once you convert to upper case, e.g. abc and aBC both become ... it depends in which shell you're using. ...
    (comp.unix.shell)
  • Re: tr
    ... > You may need to put single ticks around the tr args, depending on ... > clashes once you convert to upper case, e.g. abc and aBC both become ... it depends in which shell you're using. ...
    (comp.unix.shell)
  • [9fans] win execution behaviour in acme
    ... win -e cmd1 args ... ... get four separate `win' windows, ... running the separate commands. ...
    (comp.os.plan9)
  • Re: Hiding symbols in shared library
    ... Henrik Goldman wrote: ... Generally you should not separate ld options and their args with separate ... (Of course you can go crazy by combining them into all one -Wl. ...
    (comp.sys.hp.hpux)