向 Unix 命令行应用程序添加命令调用

发布于 2024-07-04 11:53:27 字数 150 浏览 7 评论 0原文

我正在开发一个用 Java6 编写的 Solaris 命令行应用程序。 我希望能够使用向上和向下箭头滚动浏览以前命令的历史记录,就像许多 Unix 工具允许的那样(shell、VIM 命令模式提示符等)。

有没有任何标准方法可以实现这一目标,还是我必须自己推出?

I'm working on a command line application for Solaris, written in Java6. I'd like to be able to scroll through a history of previous commands using the up and down arrows like many Unix tools allow (shells, VIM command mode prompt, etc).

Is there any standard way of achieving this, or do I have to roll my own?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

阳光①夏 2024-07-11 11:53:27

ledit 在 Linux 上非常适合这类事情。 它可能很容易在Solaris 上编译。

澄清:ledit 包装对其他命令行应用程序的调用,甚至可以传递一个文件来持久存储您的历史记录。

这是主页:http://cristal.inria.fr/~ddr/ledit/

ledit is great on linux for that sort of thing. It's probably easily compiled on solaris.

Clarification: ledit wraps the call to your other command line app, and can even be passed a file to persistently store your history.

Here's the homepage: http://cristal.inria.fr/~ddr/ledit/

懒猫 2024-07-11 11:53:27

有一个 SourceForge 项目 http://java-readline.sourceforge.net/,它提供了基于 JNI 的 GNU readline 绑定。 我已经使用过它(未在实际项目中使用),它当然涵盖了所有功能。

There is a SourceForge project, http://java-readline.sourceforge.net/, that provides JNI-based bindings to GNU readline. I've played around with it (not used in an actual project), and it certainly covers all of the functionality.

稳稳的幸福 2024-07-11 11:53:27

警告:GNU readline 受 GPL 许可条款约束:

Readline 是免费软件,分布式
根据 GNU 通用条款
公共许可证,版本 2。这意味着
如果你想在
您发布或分发的程序
对任何人来说,该程序必须是免费的
软件并具有 GPL 兼容
执照。 如果您需要以下方面的建议
使您的许可证兼容 GPL,
联系[电子邮件受保护]

换句话说,使用 Readline 将 GPL 性从库传播到整个程序。 (与 LGPL 相比,LGPL 允许运行时链接到库,并且仅在改进库本身时才需要开源。)

对于我们这些商业世界中的人来说,即使我们不开发商业应用程序,这也是一场表演-塞子。

无论如何,维基百科页面列出了几个替代方案,包括听起来很有前途的 JLine。

顺便说一句:我在一家设计医疗产品的公司工作。 我们通过 PC 软件赚取零 (0) 美元。 几乎我们所有的软件都在我们设计的嵌入式系统上运行(我们不会从该软件的销售/升级中获利,只从产品本身中获利); 有时我们确实有可以在最终用户的电脑上运行的软件诊断工具。 (未向客户发布的设计/制造/测试软件,我认为可能可以使用 GPL 库,但我不确定)医疗产品有相当严格的控制; 你基本上必须向 FDA 证明它对用户是安全的,最终用户不能决定“哦,我不喜欢这个软件,我只是调整它或使用 XYZ 公司的售后替代品”——这会让设备制造商承担巨大的责任。

warning: GNU readline is subject to GPL licensing terms:

Readline is free software, distributed
under the terms of the GNU General
Public License, version 2. This means
that if you want to use Readline in a
program that you release or distribute
to anyone, the program must be free
software and have a GPL-compatible
license. If you would like advice on
making your license GPL-compatible,
contact [email protected].

In other words, use of Readline spreads the GPL-ness from a library to the entire program. (Contrast with LGPL, which allows runtime linking to a library, and requires open-sourcing only for improvements to the library itself.)

For those of us in the commercial world, even if we're not developing commercial applications, this is a show-stopper.

Anyway, the wikipedia page lists several alternatives, including JLine, which sounds promising.

Just as an aside: I work for a company that designs medical products. We make zero (0) dollars off of PC software. Nearly all our software runs on the embedded systems that we design (and we don't make any money off sales/upgrades of this software, only the products themselves); sometimes we do have software diagnostic tools that can run on the end-users' PCs. (design/manufacture/test software that's not released to customers I would think might be possible to use GPL libraries but I'm not sure) Medical products have fairly tight controls; you basically have to prove to the FDA that it's safe for users, it's not like the end user can decide "oh, I don't like this software, I'll just tweak it or use company XYZ's aftermarket replacement" -- that would leave device manufacturers open to a huge liability.

倥絔 2024-07-11 11:53:27

是的,使用 GNU readline 库。

Yes, use the GNU readline library.

寂寞笑我太脆弱 2024-07-11 11:53:27

我认为您正在寻找类似 JLine 的东西,但我从未使用过它,因此无法证明其质量。

她显然可以处理自动完成和命令行历史记录,并且最后一个版本是最近(今年二月)所以它绝不是死的。

I think you are looking for something like JLine but I've never used it so cannot attest to its quality.

She can apparently deal with autocompletion and command line history, and the last release was recently (feb this year) so it's by no means dead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文