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



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


.



Relevant Pages

  • Re: FAQ 8.28 How can I call backticks without shell processing?
    ... s> Uri Guttman wrote: ... s> I think you meant to have "echo" not 'echo', although the result, i ... string passed to perl -e. ... they are all using the same internal call to exec which bypasses the ...
    (comp.lang.perl.misc)
  • Re: [9fans] Re: patch/list sorry/proc-mtime
    ... in C by 20h and a version by f2f in perl, ... cpu hogs, but russ's point about ls -lt /proc's uselessness is bang ... cat $i/status && echo $i ...
    (comp.os.plan9)
  • Re: Unwanted Paste behavior
    ... But the app ... Usually if I leave Bat/CMD I go to Perl since it is so much easier than ... or at the command prompt. ... What's odd is that Echo. ...
    (microsoft.public.windows.server.general)
  • Re: Help on Perl Scripting
    ... Im trying to convert c shell script to PERL but haven't use PERL ... echo "Create backup directory..." ...
    (comp.lang.perl.misc)
  • Re: how to copy a database
    ... I does not have to be Perl, ... I use the command line utilities that come with MySQL: ... echo Password: ... echo Restored MySQL db %1 ...
    (perl.dbi.users)