调用Perl脚本中的一个Jar文件(Java文件)。

huangapple go评论75阅读模式
英文:

invoke a jar file(java file) from perl script

问题

我正在使用Eclipse,我需要从Perl脚本中调用一个jar文件。

#!"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);

这是我在Perl文件(echo.pl)中使用的代码,用于调用jar文件。请问是否存在任何错误在这段代码中:"C:\Users\RajendraPrasadH\eclipseworkspace\ApplicationProtector\target\ApplicationProtector-0.0.1-SNAPSHOT.jar",这是jar文件所在的路径。

英文:

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 .

答案1

得分: 1

OP的代码中存在双引号错误的情况,use strictuse warnings 将会警告可能的问题。

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;

输出:

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解释器对双引号字符串进行了插值,通过展开反斜杠序列。

修正后的@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;

输出:

Content-Type: text/html

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

更自然的方式是这样写代码:

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);

输出:

Content-Type: text/html

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

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

huangapple
  • 本文由 发表于 2020年3月15日 20:42:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/60692993.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定