Re: FAQ 8.28 How can I call backticks without shell processing?
- From: "szr" <szrRE@xxxxxxxxxxxxxxx>
- Date: Fri, 4 Jul 2008 07:37:10 -0700
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
.
- Follow-Ups:
- Re: FAQ 8.28 How can I call backticks without shell processing?
- From: Uri Guttman
- Re: FAQ 8.28 How can I call backticks without shell processing?
- References:
- FAQ 8.28 How can I call backticks without shell processing?
- From: PerlFAQ Server
- Re: FAQ 8.28 How can I call backticks without shell processing?
- From: szr
- Re: FAQ 8.28 How can I call backticks without shell processing?
- From: Uri Guttman
- FAQ 8.28 How can I call backticks without shell processing?
- Prev by Date: FAQ 8.22 Why do setuid perl scripts complain about kernel problems?
- Next by Date: Re: Formatting ASCII to be read by Windows NotePad
- Previous by thread: Re: FAQ 8.28 How can I call backticks without shell processing?
- Next by thread: Re: FAQ 8.28 How can I call backticks without shell processing?
- Index(es):
Relevant Pages
|