0
我在Eclipse(tomcat8 localhost)中使用JAX-WS,我需要从中调用Perl脚本。使用下面的代码,我能够达到Match.pl的前三行。但是,当它达到use Stats;
时,过程返回退出值2.无法从Java代码调用Perl脚本
Stats.pm文件与Match.pl文件位于同一目录中,该文件已通过hello.sh脚本导出到PERL5LIB。
我在做什么错?有没有办法使用相对路径而不是绝对路径?
@Path("/")
public class MyService {
@POST
@Path("/generatePath")
@Produces(MediaType.TEXT_PLAIN)
public Response generatePathService(
@FormParam("url") String fileURL) throws IOException, InterruptedException {
Process p0 = Runtime.getRuntime().exec("sh /home/me/workspace/MyService/hello.sh");
p0.waitFor();
Process p = Runtime.getRuntime().exec("perl /home/me/workspace/MyService/Match.pl");
p.waitFor();
return Response.status(200).entity(fileURL).build();
}
}
Match.pl
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Stats;
Stats.pm
#!/usr/bin/perl
package Stats;
use strict;
use warnings;
hello.sh
#!/bin/bash
export PERL5LIB=/home/me/workspace/MyService
是perl在你的路径吗?有什么异常? –
是的,perl在路径中(并且部分为Match.pl运行)。我看不到任何来自Eclipse的异常 – Arturo
我的猜测是在运行perl脚本之前没有完成导出 – Arturo