Java里的方法如下:
public String execPerl(String filename){
String cmd;
String msg = "";
String brs = "";
cmd = "perl " + filename;
try{
Process prc = Runtime.getRuntime().exec(cmd);
InputStream ins = prc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(ins));
while((brs=br.readLine())!=null)
{
msg += msg + brs ;
}
}
catch(IOException ioexception) {
return ioexception.getMessage();
}
return msg;
}
JSP 页面:
Conperl conperl = new Conperl();
String filename = "D:/perlStudy/createfile.pl";
String ret = conperl.execPerl(filename);
%>
在Windows下,我放在tomcat 的 webapp 目录下可以顺利获得返回的信息
在Linux下,我把jsp改成
Conperl conperl = new Conperl();
String filename = "/usr/test/createfile.pl";
String ret = conperl.execPerl(filename);
%>
页面就什么结果也没,好象没执行一样,是不是路进没找到?
但我在Linux console下运行 perl /usr/test/createfile.pl 是可以获得信息的