英文:
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 strict
和 use 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论