用于调用外部程序的Java库
我正在寻找一个有助于运行外部程序的JAVA库。现在我在单独的线程中“手动”运行它们并捕获 I/O。
我有几个不同的外部工具要运行,我需要的是一个统一的方法来执行此操作。我要处理的任务包括: - 根据预定义的模板准备输入文件 - 运行命令 - 等待结果并解析输出文件 - 维护管道
整个管道可以被视为一个图,以外部工具为节点,以数据流为边。如果数据流允许的话,如果软件能够在并行线程中运行某些命令,那就太好了。
此类问题是否有现成的解决方案?
根据我得到的答案,我觉得我必须澄清:我不需要管道。数据流可以用文件来解决,反正我需要文件。此外,管道必须是线性的(1 个输出 -> 1 个输入),但我需要一个图表,
我已经有了 python 中的一种原型 - 一堆脚本。这很好,但对我来说 - 不可扩展。而且我调用的一些程序是用java编写的,所以用java编写整个程序会很方便。 最好的, 蒂姆
I am looking for a JAVA library that facilitates running external programs. Now I run them "manually" in a separate thread and capture I/O.
I have several different external tools to run and what I need is a uniform approach to do that. The tasks I have to handle includes:
- preparing input files according to predefined templates
- running the commands
- waiting for the results and parsing output files
- maintaining the pipeline
The whole pipeline can be considered as a graph with external tools as nodes and data flow as edges. It would be great if the software could run some of the commands in parallel threads, if the data flow permits.
Is there an existing solution of such problems?
Based on the answers I got I feel I have to clarify: I don't need pipes. Data flow can be solved with files, which I need anyway. Moreover, pipes have to be linear (1 output -> 1 input) but I need a graph
I already have a kind of a prototype in python - a bunch of scripts. It is good but as for me - not scalable. Moreover some of the programs I call are in java, so making the whole thing in java would be handy.
Best,
Tim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 Unix,您是否考虑过动态构建 Unix shell 命令行(使用管道、重定向、tee 等),然后使用 ProcessBuilder 生成这一命令> 或类似的,以及(例如)
/bin/sh -c
?这意味着您正在利用现有的工作基础设施来处理管道、缓冲、错误收集和管理资源。
If you're on Unix, have you thought about building a Unix shell command line dynamically (using pipes, redirection,
tee
etc.) and then spawning this one command off usingProcessBuilder
or similar, and (say)/bin/sh -c
?It means you're making use of an existing working infrastructure that handles pipes, buffering, error collection and managing resources.
我认为 ant 应该非常适合这个。它还具有相当好的java库来进行文件处理。在这之间,也许速度模板,我认为你应该能够做你想做的事。
I would think ant should be perfect for this. It also has fairly good java library to do file processing. Between that and maybe velocity templates, i would think you should be able to do what you want.