• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need perl help concerning error status

GundamW

Golden Member
I am using JAVA (Runtime.exec()) to execute a perl script which uses system() to execute a ftp command.

The ftp command consist of ("\n" separated) open, user, cd, mkdir, mget/mput, etc and then bye.
The perl script system() function will execute that single ftp command.

My question is:
Does perl know if any part of the ftp command failed? e.g. if "cd <directory>" failed but the rest of the ftp command works, does perl get some kind of error status/number from the system()?

The only thing I can do right now is pipe the ftp outputs to a log file and check it manually. Is there a different way?

I would hate to use JAVA to open the log file and look for error messages.

Any help would be appreciated.

Thanks.

 
Why on earth are you using system to ftp from inside perl?

What you should use is Net::FTP. I really don't see how you are sending the commands to `ftp' through system.
 
What you should use is Net::FTP. I really don't see how you are sending the commands to `ftp' through system.

You can open the command with a | and it'll print whatever you want to that programs stdin, makes it really easy to do what he's doing.

But yes, Net::FTP is the better choice.
 
Does perl know if any part of the ftp command failed? e.g. if "cd <directory>" failed but the rest of the ftp command works, does perl get some kind of error status/number from the system()?

You can check the resultant "error level" of an application simply by looking at the 'errorlevel' environment var. It should be 0 for success, 1 for failure (for EXIT_SUCCESS and EXIT_FAILURE defined in stdlib.h, respectively).

I just tried to print it through perl using both of the following:

use Env qw(ERRORLEVEL);
print $ERRORLEVEL;

and...

print $ENV{ERRORLEVEL};

No luck w/ either. Anyone have any ideas? As an interim solution, you could do...

$errorlevel = `echo %errorlevel%`;

Although that's not very clean, imo. Thrice the recommendation for Net::FTP, or code one up yourself employing java.net.*. There are many classes out there that encapsulate the rather simple protocol.

Worst case, you could use JNI to call a native library encapsulating calls to FtpGetFile()/FtpPutFile()/etc.; part of the win32 api.

[edit]
I just realized I ignorantly assumed windows was your target platform.

#ifndef WIN32
#error Ignore all of the above
#endif
[/edit]
 
Originally posted by: Nothinman
What you should use is Net::FTP. I really don't see how you are sending the commands to `ftp' through system.

You can open the command with a | and it'll print whatever you want to that programs stdin, makes it really easy to do what he's doing.

But yes, Net::FTP is the better choice.

Yes, but that would require him to use open and not system and the error checking on this would be a horrible mess compared to using Net::FTP. Besides it really doens't make sense to use perl to open ftp from Java, it's not like Java isn't slow enough in itself . 🙂
 
Yes, but that would require him to use open and not system

True.

Besides it really doens't make sense to use perl to open ftp from Java, it's not like Java isn't slow enough in itself .

Also true, he should write the whole thing in either perl or java and use one of the available FTP modules.
 
Originally posted by: Rias
Why on earth are you using system to ftp from inside perl?

What you should use is Net::FTP. I really don't see how you are sending the commands to `ftp' through system.

Thanks for the advice guys.
Unfortunately we are using perl version 5.005_03 build and I can't switch to a newer version of perl for now. The only thing I can change is either the JAVA (v1.3) code or the perl code.

I will just use the whatever log file we have for checking errors. Thanks.
 
Back
Top