tshark命令行将wireskark pcap文件转换为文本文件

时间:2016-05-11 13:49:43

标签: pcap

我正在尝试使用tshark命令行将wireskark pcap文件转换为文本文件。一切都很正常。但我没有输出也没有错误

public void convertPcapToTxt( )  {
  try {
    // setting output and input file names
    String resultfile = "C:\\MY.txt";
    String pcapfile = "C:\\MY.pcap";
    Runtime rt = Runtime.getRuntime();
    // create output
    PrintStream out = new PrintStream(resultfile);
    // set command line
    Process proc = rt.exec("tshark.exe -V -r " + pcapfile);
    //output to file
    BufferedReader stdInput = new BufferedReader
                             (new InputStreamReader(proc.getInputStream()));
     String s = null;
     while ((s = stdInput.readLine()) != null) {
      out.println(s);
     }
   //close output
   out.close();
   } catch (IOException io) {
      io.printStackTrace();
   } 
}

1 个答案:

答案 0 :(得分:0)

public void convertPcapToTxt(File file, String pcapfile) {
  try {
    PrintStream out = new PrintStream(new FileOutputStream(file));
    Runtime rt = Runtime.getRuntime();
    String commands = "tshark.exe -V -r \"" + pcapfile + "\"";
    Process proc = rt.exec(commands);
    BufferedReader stdInput = new BufferedReader
                             (new InputStreamReader(proc.getInputStream()));

    String s = null;
    while ((s = stdInput.readLine()) != null) {
        out.println(s);
    }
    out.close();
  } catch (IOException io) {
     io.printStackTrace();
  }
}