java - 从 perl 脚本调用 jar 文件(java 文件)
问题描述
我正在使用 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 文件所在的路径。
解决方案
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
推荐阅读
- swift - SkScene 未显示所有子节点和不正确的节点数
- c# - 如何从泛型类的方法中调用类 T 的非泛型方法?
- blockchain - 智能合约可以访问其他区块链的数据吗?
- python - Python Dataframes:数据列被错误地读取为行索引,并且 reset_index() 产生错误的输出
- python - 如何在 sympy 中创建抽象的元素向量函数
- javascript - 未处理的拒绝(TypeError):无法读取未定义的属性“投票”
- javascript - 在 React.js 中拖动时如何更改光标 CSS
- java - 领域驱动设计 AggregateRoot 选择
- python - 安装和配置 GeoDjango 的问题
- sql-server - 在 Visual Studio (SQL Server) 中返回标识值