Guille Guille - 5 months ago 3x
Perl Question

Execute Perl script from Java tomcat returns ever 255 exit code

I have a problem, I'm trying to execute a PERL script allocated on another server. If I execute the command in Linux Shell, the script run correctly. If I execute the script allocating the perl script in the same server of apache Tomcat, runs ok, but when I try to execute the script through ssh by Tomcat, always end with error code 255.

Perl Script:

my $sleeptime = 10;

my $argumento=$ARGV[0];
if ( $argumento eq "A" ) {
exit 0;
} else {
exit 192;

Now, this is the code in Java file

String command = "ssh '/usr/bin/perl /var/www/ A'";
process = Runtime.getRuntime().exec(command);
if ( process.exitValue() == 0 ) {
System.out.println("Show icon ok");
} else {
System.out.println("Show error");

If I change command variable to

String command = "/usr/bin/perl /var/www/ A";

The return code is ok ( 0 or 192 )

Is mandatory to execute remotely, so I can't copy the real PERL to tomcat directory. I did localy just for test.


Did you try the SSH call from the Tomcat server as the tomcat user, e.g.

ssh '/usr/bin/perl /var/www/ A'

Try adding -v as ssh argument and capture the output to see if the ssh connection is working. Maybe you're missing RSAAuthentication (key-based instead of password-based) or something else doesn't work as it should.

Try returning some value from Perl for debugging:

print "I'm running (STDOUT)\n";
print STDERR "I'm running (STDERR)\n";