首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

java中怎么调用perl脚本

2013-04-20 
java中如何调用perl脚本public class ReadPerl {public static void main(String[] args) throws IOExcept

java中如何调用perl脚本

public class ReadPerl {
public static void main(String[] args) throws IOException {

StringBuffer resultStringBuffer = new StringBuffer();
String lineToRead = "";
int exitValue = 0;
try {
Process proc = Runtime.getRuntime().exec("perl D:\\myperl.pl");
InputStream inputStream = proc.getInputStream();
BufferedReader bufferedRreader = new BufferedReader(new InputStreamReader(inputStream));

// save first line
if ((lineToRead = bufferedRreader.readLine()) != null) {
resultStringBuffer.append(lineToRead);
}

// save next lines
while ((lineToRead = bufferedRreader.readLine()) != null) {
resultStringBuffer.append("\r\n");
resultStringBuffer.append(lineToRead);
}

// Always reading STDOUT first, then STDERR, exitValue last
proc.waitFor(); // wait for reading STDOUT and STDERR over
exitValue = proc.exitValue();
} catch (Exception ex) {
resultStringBuffer = new StringBuffer("");
exitValue = 2;
}

System.out.println("exit:" + exitValue);

System.out.println(resultStringBuffer.toString());

}

}

为什么没有反应啊?lineToRead 一直是空值。绝对不是路径问题,D盘有myperl.pl这个文件 Java Perl
[解决办法]
Process proc = Runtime.getRuntime().exec("cmd /c start perl D:\\myperl.pl");或者
Process proc = Runtime.getRuntime().exec("cmd /c perl D:\\myperl.pl");

热点排行