gpt4 book ai didi

java - JTextPane 输出奇怪的控制台字符

转载 作者:太空宇宙 更新时间:2023-11-04 09:20:20 24 4
gpt4 key购买 nike

我试图在 Kali linux 中运行控制台命令,但是当我将它通过管道传输到 JTextPane 时,输出很奇怪。当我在 Netbean 的输出控制台上显示它时,它很好。

我尝试运行的命令:wifite -e Experiment -c 1

enter image description here

代码:

    public cracker(JTextPane aOutputPane)
{
super();
mOutputPane = aOutputPane;
}
@Override
protected String doInBackground() throws Exception
{
Process p = null;
try
{
String Channel=CNinput.getText();
String WName=WN.getText();
p = Runtime.getRuntime().exec("wifite -e "+WName+" -c "+Channel);
}
catch (IOException ex)
{
Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex);
}
BufferedReader buf = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
String output = "";
try
{
while ((line = buf.readLine()) != null)
{
publish(line);
output += line + "\n";
}
}
cat

ch (IOException ex)
{
Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex);
}
try
{
p.waitFor();
}
catch (InterruptedException ex)
{
Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex);
}
return output;
}
@Override
protected void process(java.util.List<String> aChunks)
{
mOutputPane.setText(null);
final String intermediateOutput = aChunks.stream().collect(Collectors.joining("\n"));
final String existingText = mOutputPane.getText();
final String newText = existingText + "\n" + intermediateOutput;
mOutputPane.setText(newText);

}

}

最佳答案

字符是ANSI escape codes , 旨在控制 wifite 生成的终端输出的外观。在您的选择中,

  • 在您的 doInBackground() 实现中删除字符序列;它们都以 ESC 开头性格。

  • 检查代码并在您的JTextPane中重述相应的样式,如StyledDocument所示here .

  • 使用像 NetBeans console 这样的库或 Jansi,引用 here .

关于java - JTextPane 输出奇怪的控制台字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42650801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com