Assign program result or die

M

Martin Nilsson

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
 
J

Jürgen Exner

Martin said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top