• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to run tshark command in java on ubuntu

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am trying to run tshark command using runtime environment in java on ubuntu . My code is as follows :-


try {
String destip = map1.get((String) innObj.get("value"));
Runtime run = Runtime.getRuntime();
String tshk = "/usr/bin/tshark -r /home/pratibha/Desktop/vox.pcap -Y \"ip.dst == "
+ destip
+ " && http\" -T fields -e tcp.port -e col.Info";
Process pr = run.exec(tshk);

int exitcode = pr.waitFor();
System.out.println(exitcode);
BufferedReader buf = new BufferedReader(
new InputStreamReader(pr.getInputStream()));

String line = "";
while ((line = buf.readLine()) != null) {
System.out.println(line);
}

} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


map1 is hashmap which contains the destination ip adress
When i run the above code the exit code for process (pr) is 1 and hence the tshark command is not executing properly.
Please help
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try printing out the inputStream and errorStream to see if that gives you any more information about why it is not working.
You need to do this before the process ends, which means before waitFor returns.

You might also want to read When Runtime.exec won't
 
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a -Y option with tshark -- did you mean -R?

Try running your command line from the shell prompt and see what happens.
/usr/bin/tshark -r /home/pratibha/Desktop/vox.pcap -Y "ip.dst == XXX.XXX.XXX.XXX && http" -T fields -e tcp.port -e col.Info
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic