471,119 Members | 1,123 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

Assign program result or die

Hi,

I'm new to Perl and have a question about return statuses and
errorhandling. I want to do the following.

Execute a program and assign the result to an array and if the program
return an error I want to show the error. Something like this:

my @files = system("$ncftpls -1 -u $USER -p $PASSW
ftp:\/\/$HOST$remote_dir") && die "Could not execute NcFTPLS. Error:
$????";

Of course this does not work but maybe it shows what I want to do? How
do I get the error code ($????) from the program $ncftpls and how
should I write the code?

For info: $ncfptls is NcFTPLS found at http://www.ncftp.com/

Any hints?

Br,

Martin
Jul 19 '05 #1
1 3520
Martin Nilsson wrote:
I'm new to Perl and have a question about return statuses and
errorhandling. I want to do the following.

Execute a program and assign the result to an array and if the program
Do you mean result (= return value) or do you mean output?
return an error I want to show the error. Something like this:
You may want to read the first example in the man page for system().
my @files = system("$ncftpls -1 -u $USER -p $PASSW
ftp:\/\/$HOST$remote_dir") && die "Could not execute NcFTPLS. Error:
$????";
This assignment probably does not do what you assume it would do.
Please read the third and following sentences in the third paragraph of the
perldoc page for system().

Of course this does not work but maybe it shows what I want to do? How
do I get the error code ($????) from the program $ncftpls and how
should I write the code?
Assuming with "error code" you actually mean the return value, then please
read the first two and maybe the last sentence in the third paragraph of the
perldoc page for system().
Any hints?


Yep. Read the manual for the functions you are using: "perldoc -f system"
explains it all.

jue
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by steflhermitte | last post: by
18 posts views Thread by joaotsetsemoita | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.