Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Space in directory-name (http://www.velocityreviews.com/forums/t138230-space-in-directory-name.html)

Gordon Beaton 11-08-2004 08:20 AM

Re: Space in directory-name
 
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

Oliver Hirschi 11-08-2004 08:59 AM

Space in directory-name
 
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 11-08-2004 09:34 AM

Re: Space in directory-name
 

"Gordon Beaton" <not@for.email> schrieb im Newsbeitrag
news:418f3a76$1@news.wineasy.se...
> 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



All times are GMT. The time now is 04:35 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.