我应该如何在Java中调用Perl脚本? [英] How should I call a Perl Script in Java?

查看:469
本文介绍了我应该如何在Java中调用Perl脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读 Runtime.getRuntime()。exec(perl script.pl)是一个选项,但这是最好的方法吗?



我需要来自该脚本的答案,所以在某些情况下我必须阅读脚本的返回,尽管我可能会在其他案例中从文本文件中读取它。 / p>

无论如何, exec()从Java调用Perl脚本的好方法是什么?我应该注意,我正在研究Java Web应用程序,因此安全性是一个问题。

解决方案

你可以使用< a href =http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html =noreferrer> 运行时 .getRuntime() .exec() 或使用 Process API
Process API允许您获取脚本的输出,因此您可以同时进行通信。



exitValue() getInputStream() 似乎就是你所需要的。


I read Runtime.getRuntime().exec("perl script.pl") is an option, but is this the best way to do it?

I'll need an answer from that script, so I'll have to read the script's return in some cases, although I might read it from a text file on other cases.

Anyway, is exec() a good way of calling a Perl Script from Java? I should note, I'm working on a Java Web Application, so security is an issue here.

解决方案

You can use Runtime.getRuntime().exec() or use the Process API. The Process API allows you to get the output of the script, so you can have both communicate.

exitValue() and getInputStream() seems to be what you need.

这篇关于我应该如何在Java中调用Perl脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆