Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: unable to run tshark command in java on ubuntu

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default unable to run tshark command in java on ubuntu

    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


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: unable to run tshark command in java on ubuntu

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: unable to run tshark command in java on ubuntu

    Separate the command line arguments. Suggested Reading:
    ProcessBuilder (Java Platform SE 7 )
    And I would not recommend running consecutive commands that depend upon a previous in a single exec operation - these operate at the shell level. If you must, I would recommend writing a script file containing the commands and then executing that script using ProcessBuilder or Runtime.exec

  4. #4
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: unable to run tshark command in java on ubuntu


  5. The Following User Says Thank You to Darryl.Burke For This Useful Post:

    copeg (September 19th, 2014)

  6. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: unable to run tshark command in java on ubuntu

    Quote Originally Posted by copeg View Post
    Separate the command line arguments. Suggested Reading:
    ProcessBuilder (Java Platform SE 7 )
    And I would not recommend running consecutive commands that depend upon a previous in a single exec operation - these operate at the shell level. If you must, I would recommend writing a script file containing the commands and then executing that script using ProcessBuilder or Runtime.exec


    Hey Thanks , I am getting the result now after writing a shell script .. Thank You very much !!

Similar Threads

  1. Unable to play video in JPanel using vlcj in ubuntu 13.04
    By Vabhi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 15th, 2014, 01:09 PM
  2. How to run Telnet Command in java?
    By sathish thota in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 31st, 2014, 01:17 PM
  3. how to run a command in ubuntu terminal
    By bean in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 6th, 2014, 09:19 AM
  4. Please help me! i am unable to compile and execute java files in command prompt
    By Sunanda Naik in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 24th, 2013, 08:42 AM
  5. unable to get idle time using JNA for ubuntu 11.10 onwards
    By raaz_0123 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 22nd, 2013, 03:37 AM