Space in directory-name

Discussion in 'Java' started by Gordon Beaton, Nov 8, 2004.

  1. On Mon, 8 Nov 2004 09:59:49 +0100, Oliver Hirschi wrote:
    > I have got a problem with a space in a directory-name under MacOS X.
    > I have to set the Permissions onto a directory:
    > --------------------------------------------------
    > String sPath = "/Temp/Web App/Repository/";
    > Runtime r = Runtime.getRuntime();
    > r.exec("chmod -R 777 "+sPath);
    > --------------------------------------------------
    >
    > It works fine, as long as there is no space in sPath. If there is a
    > space in sPath, the permisions are not setted.


    That's because the version of exec() you've chosen tokenizes the
    command line based only on whitespace, so your pathname gets broken
    into two (or more) separate arguments.

    You can avoid the primitive tokenization by doing it yourself:

    String[] cmd = {
    "chmod",
    "-R",
    "777",
    sPath
    };

    Process p = Runtime.getRuntime().exec(cmd);

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Nov 8, 2004
    #1
    1. Advertising

  2. Hi netpeople...

    I have got a problem with a space in a directory-name under MacOS X. I
    have to set the Permissions onto a directory:
    --------------------------------------------------
    String sPath = "/Temp/Web App/Repository/";
    Runtime r = Runtime.getRuntime();
    r.exec("chmod -R 777 "+sPath);
    --------------------------------------------------

    It works fine, as long as there is no space in sPath. If there is a
    space in sPath, the permisions are not setted.

    I tried also the following versions (...sadly without success):

    r.exec("chmod -R 777 '"+sPath+"'");
    r.exec("chmod -R 777 \""+sPath+"\"");
    r.exec("chmod -R 777 "+sPath.replaceAll(" ", "\\\\ "));

    Best thanks for all your help!

    Regards,
    --
    Oliver Hirschi
    http://www.FamilyHirschi.ch
    Oliver Hirschi, Nov 8, 2004
    #2
    1. Advertising

  3. "Gordon Beaton" <> schrieb im Newsbeitrag
    news:418f3a76$...
    > On Mon, 8 Nov 2004 09:59:49 +0100, Oliver Hirschi wrote:
    > > I have got a problem with a space in a directory-name under MacOS X.
    > > I have to set the Permissions onto a directory:
    > > --------------------------------------------------
    > > String sPath = "/Temp/Web App/Repository/";
    > > Runtime r = Runtime.getRuntime();
    > > r.exec("chmod -R 777 "+sPath);
    > > --------------------------------------------------
    > >
    > > It works fine, as long as there is no space in sPath. If there is a
    > > space in sPath, the permisions are not setted.

    >
    > That's because the version of exec() you've chosen tokenizes the
    > command line based only on whitespace, so your pathname gets broken
    > into two (or more) separate arguments.
    >
    > You can avoid the primitive tokenization by doing it yourself:
    >
    > String[] cmd = {
    > "chmod",
    > "-R",
    > "777",
    > sPath
    > };
    >
    > Process p = Runtime.getRuntime().exec(cmd);
    >
    > /gordon


    Thanks a lot...It solves my problem...

    Regards, Oli
    Oliver Hirschi, Nov 8, 2004
    #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. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,846
    Bryan Bullard
    Jul 11, 2003
  2. Christian Seberino
    Replies:
    21
    Views:
    1,604
    Stephen Horne
    Oct 27, 2003
  3. Ian Bicking
    Replies:
    2
    Views:
    966
    Steve Lamb
    Oct 23, 2003
  4. Ian Bicking
    Replies:
    2
    Views:
    694
    Michael Hudson
    Oct 24, 2003
  5. Anthra Norell

    What is the name of the name space I am in?

    Anthra Norell, Jul 5, 2010, in forum: Python
    Replies:
    0
    Views:
    258
    Anthra Norell
    Jul 5, 2010
Loading...

Share This Page