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

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

问题描述

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

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.

无论如何,exec() 是从 Java 调用 Perl 脚本的好方法吗?我应该注意,我正在开发 Java Web 应用程序,因此这里的安全性是一个问题.

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.

推荐答案

您可以使用 运行时.getRuntime().exec() 或使用 进程 API.Process API 允许您获取脚本的输出,因此您可以进行通信.

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()getInputStream() 似乎是你所需要的.

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

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

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