1

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 .

4
  • 1
    What happens when you put a use warnings; at the top of your script like you should be doing? Commented Mar 15, 2020 at 13:40
  • 1
    Have you tried printing out @args to see what it holds? Commented Mar 15, 2020 at 13:41
  • @Prasad - is there a reason why you use " in my @args = (....)? Commented Mar 15, 2020 at 17:59
  • @Prasad - try to use my @args = qw/java -jar C:\Users\RajendraPrasadH\eclipseworkspace\ApplicationProtector\target\ApplicationProtector-0.0.1-SNAPSHOT.jar/; instead and see result. Commented Mar 15, 2020 at 18:03

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

"More natural way": depends on the strings. In particular, the path could contain spaces, in which case qw// would not work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.