I want to execute a "cp" command from a perl script and in case the file does not exist I want to get and manipulate the output and do some more actions before I terminate the script.how?
Use File::Copy, it's much easier and platform independent.
Steve
[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object:erlDesignPatterns)[/small]
AFAIK, File::Copy is part of the standard perl distribution, so you should already have it. If not you can shell to the OS using system, exec or backticks (qx), try the File::Copy first, as steve says it makes your code portable ;-)
Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
Try this:
my $cmd= "cp $from $to";
my $rc= 0xffff & system (" $cmd ");
unless ($rc==0){die "cp failed !";
#you can substitute the die by whatever error hander you want
}#unless rc =0
Actually this is a step more than what you want; it says
die (or whatever erro handler you want) if the cp fails.
The cp may fail for other reasons too, like not enough space
So if all you're worried about is whether the file exists
you can do
if(-e $from){my $rc=.... ; unless($rc==0){....}#proceed
} #of -e $from
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.