pradeepbstays has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I have a perl which executes multiple UNIX command (using the system f +unction). Incase of any error in any one of the statements , I need to stop the +execution there and capture the actual error thrown. I tried using eval with $@ , but it didnt work. This is what i tried: --------------------------------------------------------- eval { system("cp xyz.dat abc.dat"); system("cp xyz.dat2 abc.dat2"); }; if ($?) { print "Error occured :".$@; print "\n"; } ~ --------------------------------------------------------- And the output is: % perl temp.perl cp: cannot access xyz.dat cp: cannot access xyz.dat2 Error occured : --------------------------------------------------------- I want the control to come out when the first copy failed.And also wan +t to cupture and log the actual error message. Can some one tell how to achive this. Thank you, Pradeep
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl exception - multiple statement
by ikegami (Patriarch) on Jul 20, 2009 at 16:55 UTC | |
| |
Re: Perl exception - multiple statement
by kennethk (Abbot) on Jul 20, 2009 at 16:30 UTC | |
by JavaFan (Canon) on Jul 20, 2009 at 16:42 UTC | |
Re: Perl exception - multiple statement
by spazm (Monk) on Jul 20, 2009 at 16:32 UTC | |
Re: Perl exception - multiple statement
by JavaFan (Canon) on Jul 20, 2009 at 16:35 UTC | |
Re: Perl exception - multiple statement
by davorg (Chancellor) on Jul 20, 2009 at 16:28 UTC |