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