JTextPane输出奇怪的控制台字符

时间:2017-03-07 14:26:24

标签: java linux swing swingworker

我试图在Kali linux中运行console命令,但是当我将它传递给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);

  }

}

1 个答案:

答案 0 :(得分:2)

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

  • 在字符序列到达doInBackground()的实现时,将其保留;它们都以ESC字符开头。

  • 检查代码并重新概述JTextPane中的相应风格,如StyledDocument所见here所示。

  • 使用引用NetBeans consolehereJansi等库。