process and spaces in filenames

Started by cormullion, December 01, 2005, 08:44:25 AM

Previous topic - Next topic

cormullion

Just before my brain packs up for the day:



(set 'f "/Users/me/folder 1/file 1") ; yes, spaces in pathnames...  

(process  (append "ls -l " f )) ; doesn't work



I need to pass some kind of quoted form of f to the shell. What's the best way of doing that?



Sorry if the question is a bit too simple...!

newdep

#1
Hi Cormullion,



Does this thread perhpas help? ->

http://www.alh.net/newlisp/phpbb/viewtopic.php?t=843">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=843



Regards, Norman.
-- (define? (Cornflakes))

Lutz

#2
Works fine for me:

> (set 'f "/Users")
"/Users"
> (process (append "ls -l " f))
1270
> total 0
drwxrwxrwt    4 root  wheel   136 Oct 20 03:36 Shared
drwxr-xr-x   45 lutz  lutz   1530 Dec  1 10:37 lutz


But it works better with 'exec', because you get the output returned in a list:

> (exec (append "ls -l " f))
("total 0" "drwxrwxrwt    4 root  wheel   136 Oct 20 03:36 Shared"
 "drwxr-xr-x   45 lutz  lutz   1530 Dec  1 10:37 lutz")
>


and you also could do this:



> (directory "/Users/")
("." ".." ".DS_Store" ".localized" "lutz" "Shared")
>


Lutz

cormullion

#3
Hi folks. Thanks for the replies. But the problem is with files and directories that have spaces in their names. (Perhaps this is a MacOS X-only thing?) So this works:



"/Applications/Firefox.app/"



but this doesn't:



"/Applications/Address Book.app/"



Loads of files and directories have spaces in, and I was looking for a way to quote them for the (process ) or (exec) functions.

newdep

#4
Unix space you have to pre with an "" like in



{/this is a directory}



Enjoy...
-- (define? (Cornflakes))

cormullion

#5
Thanks. I've also just had this inspiration:



(set 'f "/Applications/Address Book.app/")

(exec (string "ls -l " (format  "'%s'" f )))



- a way of putting single quotes round the string. If there's nothing better, that'll do nicely!

Lutz

#6
... and you could shorten that to:

(exec (format "ls -l '%s'" f ))


because format returns a string and can take other text besides format specs



Lutz

cormullion

#7
Neat. Thanks.