我的想法是做个web应用,然后调用perl去执行,最后返回结果.

现在越来越近了.

package perlexec;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class PerlExecDemo {
    public static void main(String[] args){
        System.out.print(execPerl("1.pl"));
    }
    private static String execPerl(String filename){
        String cmd="";
        String msg="";
        String brs="";
        cmd="perl "+filename;
        try{
            //设置执行perl脚本
            Process pro=Runtime.getRuntime().exec(cmd);
            //用输出流来捕获数据
            InputStream ins=pro.getInputStream();
            //捕获结果
            BufferedReader br=new BufferedReader(new InputStreamReader(ins));
            //循环把结果赋值
            while((brs=br.readLine())!=null){
                msg+=brs;
            }
        }catch(IOException e){
            //异常处理
            e.printStackTrace();
        }
        //返回最后的结果
        return msg;
    }
}

 

相关文章:

  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2021-12-12
猜你喜欢
  • 2022-01-03
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2021-07-26
  • 2021-09-27
相关资源
相似解决方案