Prasad
Prasad

Reputation: 111

invoke a jar file(java file) from perl script

Im using eclipse and i need to invoke a jar file from the perl script .

#!"C:\xampp\perl\bin\perl.exe"
print "Content-Type: text/html\n\n";
my @args = ("java", "-jar", "C:\Users\RajendraPrasadH\eclipseworkspace\ApplicationProtector\target\ApplicationProtector-0.0.1-SNAPSHOT.jar");
system(@args);

this is the code which i have used in my perl file(echo.pl) to invoke the jar file could anyone please tell me is there any mistake in this "C:\Users\RajendraPrasadH\eclipseworkspace\ApplicationProtector\target\ApplicationProtector-0.0.1-SNAPSHOT.jar" this is the path where the jar file is present .

Upvotes: 1

Views: 550

Answers (1)

Polar Bear
Polar Bear

Reputation: 6818

OP's code is perfect double quotes misuse case, use strict and use warnings would alarm about potential problem

use strict;
use warnings;
use feature 'say';

print "Content-Type: text/html\n\n";
my @args = ("java", "-jar", "C:\Users\RajendraPrasadH\eclipseworkspace\ApplicationProtector\target\ApplicationProtector-0.0.1-SNAPSHOT.jar");

say for @args;

Output

Unrecognized escape \R passed through at misuse_double_quote_1.pl line 6.
Unrecognized escape \A passed through at misuse_double_quote_1.pl line 6.
Unrecognized escape \A passed through at misuse_double_quote_1.pl line 6.
Content-Type: text/html

java
-jar
C:SERSRAJENDRAPRASADHCLIPSEWORKSPACEAPPLICATIONPROTECTOR       ARGETAPPLICATIONPROTECTOR-0.0.1-SNAPSHOT.JAR

Perl interpreter performed interpolation of double quoted string by expanding backshash sequences.

Correct code for @args = ('...','...','...')

use strict;
use warnings;
use feature 'say';

print "Content-Type: text/html\n\n";
my @args = ('java', '-jar', 'C:\Users\RajendraPrasadH\eclipseworkspace\ApplicationProtector\target\ApplicationProtector-0.0.1-SNAPSHOT.jar');
say for @args;

Output

Content-Type: text/html

java
-jar
C:\Users\RajendraPrasadH\eclipseworkspace\ApplicationProtector\target\ApplicationProtector-0.0.1-SNAPSHOT.jar

More natural way would be to write code as

use strict;
use warnings;
use feature 'say';

say "Content-Type: text/html\n";
my @args = qw/java -jar C:\Users\RajendraPrasadH\eclipseworkspace\ApplicationProtector\target\ApplicationProtector-0.0.1-SNAPSHOT.jar/;

say for @args;

system(@args);

Output

Content-Type: text/html

java
-jar
C:\Users\RajendraPrasadH\eclipseworkspace\ApplicationProtector\target\ApplicationProtector-0.0.1-SNAPSHOT.jar

Upvotes: 1

Related Questions