On Jun 15, 11:17 am, [EMAIL PROTECTED] wrote:
> Howdy,
>
> Please be gentle, I'm a perl novice to say the least.
>
> I have the following script (called bk.pl right now) :
> foreach $argnum (0 .. $#ARGV) {
>         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime
> time;
>         exec ("mysqldump --user=*** --password=*** $ARGV[$argnum] > /backups/
> $ARGV[$argnum]--$mon-$mday-$year-$hour-$min-$sec.sql");
>         exec ("tar czpf $ARGV[$argnum]--$mon-$mday-$year-$hour-$min-$sec.sql
> $ARGV[$argnum]--$mon-$mday-$year-$hour-$min-$sec");
>
> }
>
> When I run it (./scripts/bk.pl dbname) it runs the first exec
> properly, but it dose not do the second.  I get the error
> (Maybe you meant system() when you said exec()?)
>
> Any ideas as to why this is happening?

.... because you meant system() where you have exec(), just like Perl
is trying to tell you.  Do you understand the difference between the
two?

exec() executes the given program IN THE CURRENT PROCESS.  That is, it
completely destroys your existing Perl program in favor of running
this one instead.  Any code below an exec() statement (other than a
check for failure) is meaningless.  It will never be executed.

system() first creates a new process via fork().  Then in the new
process, it calls exec() to run the given program.  The original,
"parent" process waits for this "child" process to finish before
continuing.  That is, system() could be defined like so:

my $pid = fork();
if ($pid == 0) {  #child
    exec(...);
} else { #parent
    waitpid($pid, 0);
}

For more information:
perldoc -f exec
perldoc -f system
and the two that were used in my expansion:
perldoc -f fork
perldoc -f waitpid

Hope this helps,
Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to