java - 如何将 CMD 的输出逐行导入 JTextpane
问题描述
我有 textField 我在其中编写 cmd 命令,我想从导入 JtextPane 的 CMD 中获取输出结果。我明白了,但是在我执行一些命令后,整个输出会立即导入到文本窗格中,我想逐行写入,就像在 CMD 控制台中写入一样。
感谢帮助
String input = textField.getText().toString();
try {
Process p = Runtime.getRuntime().exec("cmd /c" + " " + input);
BufferedReader StdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s;
while ((s = StdInput.readLine()) != null) {
try {
Document doc = textPane.getDocument();
doc.insertString(doc.getLength(), s + "\n", null);
} catch (BadLocationException exc) {
exc.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
解决方案
推荐阅读
- oauth - 如何刷新 oauth2client.client 的 id_token?
- python - 尝试打开图像时,Tkinter“无法打开”pyimage1“:没有这样的文件或目录”错误
- postgresql - pgAdmin 找不到记录,而 SQLAlchemy 确实
- r - 试图找到一个向量的最小值
- excel - 如何遍历 Microsoft Project 任务的所有属性?
- rust - 为什么我仍然可以使用由 `move` 闭包捕获的变量?
- php - php不会上传图片?
- git - 删除不在 master::head 中的文件的历史记录
- neo4j - Neo4j cypher - 单一关系查询中的单向和双向?
- c++ - For 循环方法调用