Re: FAQ 8.28 How can I call backticks without shell processing?
- From: "szr" <szrRE@xxxxxxxxxxxxxxx>
- Date: Fri, 4 Jul 2008 11:55:46 -0700
Uri Guttman wrote:
"s" == szr <szrRE@xxxxxxxxxxxxxxx> writes:
s> Uri Guttman wrote:
"s" == szr <szrRE@xxxxxxxxxxxxxxx> writes:
perl -e '@e = qw( a b c ); open( $e, "-|", 'echo', @e ); print
<$e>'
a b c
I think you meant to have "echo" not 'echo', although the result, i
nthis case, is the same.
>> echo printed its args with spaces as expected so it got 3 separate
>> args and not 'abc' as you claim it would.
s> Curious, I thought the behavior would be like:
s> $ perl -e '@e = qw( a b c ); print @e'
s> which yields 'abc', as I saw that after the first three arguement
of the s> normal 3 arg open() it appeared to take a list of
additional args that s> is passes to what ever you opened. I didn't
know it separates them like s> it does. Good to know.
you don't get what is happening there. perl is printing each element
and there is no separator so it appears you are concatenating. when
you exec with a list each argument is separated in the same way and
it depends on the exec'ed program how they will be used. echo puts
spaces between them which is why i chose that for the one liner. i
could have used perl
again and it would not have put spaces in unless i made it do so (as
with "@e").
Seem you are correct:
opentest.pl:
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 print join(',', @ARGV), "\n";
6
$ perl -e '@e = qw(a b c); open( $e, "-|", "./opentest.pl", @e );
print <$e>'
a,b,c
It's good to know. I've been using Perl for years but I never found a
situation where I needed to use open() like that, although I should of
known it would behave like system() - each element in the array gets
passed as a separate argument to the program.
Thanks :-)
--
szr
.
- Follow-Ups:
- Re: FAQ 8.28 How can I call backticks without shell processing?
- From: Peter J. Holzer
- 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
- 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: Re: Formatting ASCII to be read by Windows NotePad
- Next by Date: FAQ 1.2 Who supports Perl? Who develops it? Why is it free?
- 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
|