Java中的命令行界面 [英] Command-line interface in Java

查看:219
本文介绍了Java中的命令行界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个跨平台解决方案,以提供对Java中的流程的输入,错误和输出流的访问。

I want to create a cross platform solution for providing access to the input, error and output streams of a Process in Java.

基本上,我想创建是一个显示Process的输出和错误流的文本区域,并允许您向输入流提供数据。换句话说,当你运行应用程序时,Eclipse已经提供了它的控制台。

Basically, what I want to create is a text area that displays the Process' output and error streams, and allows you to supply data to the input stream. In other words, pretty much what Eclipse is already providing with its Console when you run an application.

现在,一个基本的实现很容易,我简单地发送所有的键按下输入流。但是,当然,我碰到麻烦的粘贴,退格键和箭头键,处理 ctrl-C 等。

Now, a basic implementation of this was easy, I simply send all key presses to the input stream. But, of course, I ran into trouble with pasting, backspace and arrow keys, handling ctrl-C and so on.

应该在将数据发送到Process的输入流之前等待。但等待什么?我应该在每个返回键发送所有输入(和粘贴)的文本吗?或者间隔后? ctrl-C ctrl-X 等等。是否将箭头键移动发送到输入流?

It seems I should wait before sending data to the Process' input stream. But wait for what? Should I send all entered (and pasted) text at each return key? Or after an interval? What about ctrl-C, ctrl-X and so on. Do I send arrow key movement to the input stream?

推荐答案

您不应该等待任何内容,单独的线程,而不是你的GUI事件线程,所以后一个不阻塞。

You should not wait for anything, simply send - but send in a separate Thread, not your GUI-Event-thread, so the latter one does not block.

为了处理特殊字符,看看当输入这些符号时你会得到什么在文本控制台中。

For handling the special characters, look what you would get when these signs are entered in a text console.

这篇关于Java中的命令行界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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