problem in executing unix script from java

Discussion in 'Java' started by ruds, Dec 27, 2006.

  1. ruds

    ruds Guest

    hello,
    I want to find out how much free disk space is present for a particular
    directory in unix system.
    For this I'm executing command :
    p=r.getRuntime().exec("rsh "+machine+" \"cd /scratch; df -k .\" |
    awk '{print $3}' ");

    but, the '-' sign of df -k and the single quotes for print do not get
    exceuted and hence I'm not able to get a proper o/p.

    can anyone tell me how to execute it?
     
    ruds, Dec 27, 2006
    #1
    1. Advertising

  2. On 27 Dec 2006 03:29:03 -0800, ruds wrote:
    > For this I'm executing command :
    > p=r.getRuntime().exec("rsh "+machine+" \"cd /scratch; df -k .\" |
    > awk '{print $3}' ");
    >
    > but, the '-' sign of df -k and the single quotes for print do not
    > get exceuted and hence I'm not able to get a proper o/p.
    >
    > can anyone tell me how to execute it?


    Try it like this instead, using an array to group the command
    arguments properly:

    String[] cmd = { "rsh",
    machine,
    "cd /scratch; df -k . | awk '{print $3}'"
    };


    p = r.getRuntime.exec(cmd);

    /gordon

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Dec 27, 2006
    #2
    1. Advertising

  3. ruds

    ruds Guest

    Thanks, It did help me.
     
    ruds, Dec 29, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cédric Rossé
    Replies:
    1
    Views:
    534
    Cédric Rossé
    Nov 9, 2004
  2. sarmin kho
    Replies:
    1
    Views:
    378
    Cameron Laird
    Jun 4, 2004
  3. ruds
    Replies:
    4
    Views:
    706
  4. gravi2020
    Replies:
    0
    Views:
    1,820
    gravi2020
    Jan 15, 2009
  5. sunil
    Replies:
    2
    Views:
    153
    Tintin
    Dec 25, 2003
Loading...

Share This Page