SPUG: exec question
Tim Maher
tim at consultix-inc.com
Fri Feb 11 10:57:30 PST 2005
On Fri, Feb 11, 2005 at 10:10:15AM -0800, Ben Reser wrote:
> Ugh that's just ugly. And runs a shell in the process. Surely that's
> not what he really wants. From what it sounds like exec is what he
> wants, I'm not sure why it's not working right. Perhaps he's
> misunderstanding what it does. But someone else in the thread already
> mentioned it.
> Ben Reser <ben at reser.org>
> http://ben.reser.org
Exec is working properly, but it seems most of the posters in this
thread are expecting it to provide different services than it really
does:
$ perldoc -tf exec
exec LIST
exec PROGRAM LIST
The "exec" function executes a system command *and never
returns*-- use "system" instead of "exec" if you want it to
return. It fails and returns false only if the command does not
exist *and* it is executed directly instead of via your system's
command shell (see below).
Since it's a common mistake to use "exec" instead of "system",
Perl warns you if there is a following statement which isn't
"die", "warn", or "exit" (if "-w" is set - but you always do
that). If you *really* want to follow an "exec" with some other
statement, you can use one of these styles to avoid the warning:
...
-Tim
*--------------------------------------------------------------------------*
| Tim Maher, PhD (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX |
| tim(AT)Consultix-Inc.Com http://TeachMePerl.Com http://TeachMeUnix.Com |
*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*
| Watch for my upcoming book: "Minimal Perl for UNIX/Linux People" |
*--------------------------------------------------------------------------*
More information about the spug-list
mailing list