Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > spaces giving problem on Mac OS.

spaces giving problem on Mac OS.
Thread Tools
Fresh-Faced Recruit
Join Date: May 2001
Location: India
Status: Offline
Reply With Quote
May 26, 2001, 12:06 AM
 

hi,
i m opening applications on Mac OS thru the "open" command. But the
problem arises when any directory or file name contains spaces. For
example, if i have a folder named "My Folder", then any file in this
folder can not be opened through this command.

similar problem is there when file name contains spaces.

can anybody suggest, what could be the solution.
Please help. Its urgent.

Rachna
     
rw
Mac Enthusiast
Join Date: Dec 2000
Location: Kirkland, WA, USA
Status: Offline
Reply With Quote
May 26, 2001, 12:11 AM
 
Three ways to do it:

(1) Use quotation marks: open "My Folder"

(2) Use the backslash as an escape character: open My\ Folder

(3) type the first few letters then hit Tab: open My<TAB>
Dang! I forgot to uncheck the "Show Signature" button again!
     
Fresh-Faced Recruit
Join Date: Apr 2001
Location: mission, tx
Status: Offline
Reply With Quote
May 26, 2001, 12:27 AM
 
single quotes works as well...

----
life is made up of moments...this is one of them
life is made up of moments...this is one of them
     
Rachna  (op)
Fresh-Faced Recruit
Join Date: May 2001
Location: India
Status: Offline
Reply With Quote
May 26, 2001, 04:04 AM
 
Thanx for ur prompt reply.
i have tried ur suggestions on the terminal, and they are working correctly.
but when i try to invoke the same command in Runtime.getRuntime().exec() method, it still does'nt work.
For Example i have tried:
suppose i want to open "System Folder"

Runtime.getRuntime().exec("open /System\\ Folder"); // for backslash
Runtime.getRuntime().exec("open \"/System Folder\""); // for double quotes

but none of these is working.
Please help.

     
Grizzled Veteran
Join Date: Sep 2000
Location: Netherlands
Status: Offline
Reply With Quote
May 26, 2001, 09:41 AM
 
Originally posted by Rachna:

but when i try to invoke the same command in Runtime.getRuntime().exec() method, it still does'nt work.
For Example i have tried:
suppose i want to open "System Folder"

Runtime.getRuntime().exec("open /System\\ Folder"); // for backslash
Runtime.getRuntime().exec("open \"/System Folder\""); // for double quotes
Dive into the JAVA documentation.
I used this with one of my apps. http://xamba.sourceforge.net/xamba/Xamba1b3.sit
Download this app and look into the sourcefiles. It is used many times.

DJ

Derk-Jan Hartman, Student of the University Twente (NL), developer of VLC media player
     
Fresh-Faced Recruit
Join Date: May 2001
Location: Costa Luna, !*
Status: Offline
Reply With Quote
May 26, 2001, 10:47 AM
 
try: Runtime.getRuntime().exec("open /System\ Folder");

a backslash is an escape sequence, which is used to express a character that can't be directly interpreted by the shell (or by the compiler, in the case of java) because it uses that character in another context. for example, the shell uses spaces to differentiate arguments on the command line. you need to either escape the space in your filename or you need to encase the filename in quotes. one or the other, but not both. but in java, you can't encase the filename in quotes because the compiler uses quotes to delineate strings and also because the exec function doesn't use quotes to qualify a filename (um, i think).

basically you need to understand the reasons for escaping different characters in the shell and in a string in java (or any other context where you need use an escape sequence).

ok, that rambled on a little, but uh, good luck. and corrections welcome.

     
Mac Enthusiast
Join Date: Apr 1999
Location: Portland, Oregon
Status: Offline
Reply With Quote
May 26, 2001, 01:13 PM
 
Originally posted by beeduul:
try: Runtime.getRuntime().exec("open /System\ Folder");
I believe he was using two \\ 's on purpose. For example, in PHP you use one \ as an escape character, or two \\'s if you actually want a \

I dont know java at all though (and I assume that is what this is based on comments?)

everything you know is wrong (and stupid)
     
Rachna  (op)
Fresh-Faced Recruit
Join Date: May 2001
Location: India
Status: Offline
Reply With Quote
May 30, 2001, 01:32 AM
 
I have not yet got any solution to the spaces problem. I have tried to do it through double quotes and backslashs , it works fine in terminal but it is not working in my java program. And my ultimate aim is to open the applications through the java programs. For this i m using open command.

what could be the solution.
Please help. Its urgent.
Thanx


     
Mac Elite
Join Date: Mar 2001
Location: London
Status: Offline
Reply With Quote
May 30, 2001, 08:35 AM
 
Do some reading up on the sun webpage thay might be able to help also mail apple....

------------------
450DP/448MB/80GB/Rage/Apple 17"/Zip250/ZipCD/Epson740

ICQ 60617180

I Took The Red Pill
     
Admin Emeritus
Join Date: Nov 2000
Location: New Yawk
Status: Offline
Reply With Quote
May 30, 2001, 09:28 AM
 
Moving this to the OS X Developer forum. Click through to find yourself.

thanks

------------------
the oddball newsletter
------------------
it's only after you lose everything that you're free to do anything
The gem cannot be polished without friction, nor man perfected without trials.
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status: Offline
Reply With Quote
May 30, 2001, 11:31 AM
 
Try Runtime.exec(String[] cmdarray) instead, as in

String[] cmd = {"open", "/System Folder"};
Runtime.getRuntime().exec(cmd);

If the parameters need to be escaped, it should happen automatically.
     
Rachna  (op)
Fresh-Faced Recruit
Join Date: May 2001
Location: India
Status: Offline
Reply With Quote
May 30, 2001, 11:39 PM
 
My problem has been solved at last.
The syntax which did the work is:

String cmd[] = {"open", "/System Folder"};
Runtime.getRuntime().exec(cmd);

thanx very much for all ur help.
Rachna


     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:08 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2