📄 appoutputcapture.java
字号:
package source;
import java.io.InputStream;
import java.io.OutputStream;
import javax.swing.JFrame;
import javax.swing.event.CaretListener;
import javax.swing.JTextArea;
public class AppOutputCapture
{
private static Process process;
final ConsoleTextArea cta;
final JTextArea jta;
public AppOutputCapture(final JTextArea jta, final ConsoleTextArea cta)
{
this.jta = jta;
this.cta = cta;
}
public void getOutput(String[] args) throws Exception
{
if(args.length == 0)
{
System.err.println("用法:java AppOutputCapture " +
"<程序名字> {参数1 参数2 ...}");
throw new Exception("创建线程失败!");
}
try
{
// 启动命令行指定程序的新进程
process = Runtime.getRuntime().exec(args);
}
catch(Exception e)
{
throw e;
}
// 获得新进程所写入的流
final InputStream[] inStreams = new InputStream[]
{
process.getInputStream(),process.getErrorStream()
};
// 获得新进程所读出的流
final OutputStream[] outStreams = new OutputStream[]
{
process.getOutputStream()
};
cta.setStreams(inStreams, outStreams, jta);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -