newLISP Fan Club

Forum => newLISP in the real world => Topic started by: cormullion on December 01, 2005, 08:44:25 AM

Title: process and spaces in filenames
Post by: cormullion on December 01, 2005, 08:44:25 AM
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...!
Title:
Post by: newdep on December 01, 2005, 08:53:17 AM
Hi Cormullion,



Does this thread perhpas help? ->

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



Regards, Norman.
Title:
Post by: Lutz on December 01, 2005, 10:29:33 AM
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
Title:
Post by: cormullion on December 01, 2005, 11:04:05 AM
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.
Title:
Post by: newdep on December 01, 2005, 11:07:20 AM
Unix space you have to pre with an "" like in



{/this is a directory}



Enjoy...
Title:
Post by: cormullion on December 01, 2005, 11:15:42 AM
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!
Title:
Post by: Lutz on December 01, 2005, 11:18:58 AM
... 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
Title:
Post by: cormullion on December 02, 2005, 12:15:47 AM
Neat. Thanks.