Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default grep on multiple files using Runtime.getRuntime().exec()

    Hi,

    I am trying to do grep using following code:

    String[] cmd1= new String[]{"grep", "hi", "/.../sail.xx.com/fs/u/ereidl/prags/greptest*.txt"};

    Runtime rt = Runtime.getRuntime();

    proc = rt.exec(cmd1);

    but it is giving me <ERROR>
    grep: 0652-033 Cannot open /.../sail.ibm.com/fs/u/ereidl/prags/greptest*.txt.
    </ERROR>

    I am able to do grep on single file but not able to do so on multiple files using *.
    The same command when executed on unix directly works but not using java.

    Please help me solve this problem.

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Double backslash

    Try using double backslash:
    Java Code:
    "//...//sail.xx.com//fs//u/ereidl//prags//greptest*.txt"
    See if that helps any.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    or maybe File.separator?

  4. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Unforetunately, "*" is expanded by the shell, and since you are using 'exec', there is no shell to do the expanding for you.

    What you have to do, is write a script, and then exec the script. For example:

    Java Code:
    #!/bin/csh -f
    
    grep $1 $2

Similar Threads

  1. Replies: 6
    Last Post: 12-29-2008, 02:47 PM
  2. help with Runtime.exec()
    By Lanfear in forum New To Java
    Replies: 18
    Last Post: 12-16-2008, 11:09 AM
  3. Tomcat and Runtime.exec
    By karine in forum Introductions
    Replies: 1
    Last Post: 10-03-2008, 08:25 AM
  4. Runtime.exec()
    By hknyo in forum Advanced Java
    Replies: 2
    Last Post: 08-16-2008, 12:40 AM
  5. Problem with Runtime.exec()
    By nhabibi in forum Advanced Java
    Replies: 11
    Last Post: 07-02-2008, 01:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •