java代码里调用perl程序
package java_perl; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Java_Perl { /** * @param args */ public static void main(String[] args) { System.out.print(execPerl("D:\\workspace\\PerlDemo\\subroutine_10.pl")); } private static String execPerl(String fileName){ String cmd = ""; String msg = ""; String brs = ""; cmd = "perl " + fileName; try { 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; } } //perl程序 subroutine_10.pl use strict; sub division{ return $_[0]/$_[1] ; } my $result = division 24,2 ;#可以省略&号 print "$result\n";