develooper Front page | perl.perl5.porters | Postings from April 2006

Re: [perl #39011] system, exec etc unable to handle shell functions

Thread Previous
From:
Dominic Dunlop
Date:
April 27, 2006 14:07
Subject:
Re: [perl #39011] system, exec etc unable to handle shell functions
Message ID:
0D1C51BD-A9D2-48B5-9216-46264AD781F9@mac.com
Thank you for your report, but this is not a bug.

On 2006–04–27, at 11:56, Qian Cai (via RT) wrote:

> go() { echo Hello; }; export -f go; perl -w <<< 'system("go");'
>
> - Not work; Can't exec "go": No such file or directory at - line 1.
>
> go() { echo Hello; }; export -f go; perl -w <<< 'system("ls; go");'
>
> - It works, as the first command in "system" is an external command.

The difference is that, in the first example, perl sees no characters  
that are special to the shell in the argument to system(), and so  
tries to exec  go  directly. This fails because there is nothing of  
that name in the search path. In the second case, perl sees a  
semicolon, and so passes the system()'s argument to a shell to  
process, resulting in the function being found in the environment.  
You can make the first example work as you want by changing the  
argument to system to "go;", or by explicitly running a shell:

perl -w <<<'system(qw(sh -c go))'

For more information, see

perldoc -f system
-- 
Dominic Dunlop


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About