Page 1 of 1
process and spaces in filenames
Posted: Thu Dec 01, 2005 4:44 pm
by 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...!
Posted: Thu Dec 01, 2005 4:53 pm
by newdep
Hi Cormullion,
Does this thread perhpas help? ->
http://www.alh.net/newlisp/phpbb/viewtopic.php?t=843
Regards, Norman.
Posted: Thu Dec 01, 2005 6:29 pm
by Lutz
Works fine for me:
Code: Select all
> (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:
Code: Select all
> (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:
Code: Select all
> (directory "/Users/")
("." ".." ".DS_Store" ".localized" "lutz" "Shared")
>
Lutz
Posted: Thu Dec 01, 2005 7:04 pm
by cormullion
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.
Posted: Thu Dec 01, 2005 7:07 pm
by newdep
Unix space you have to pre with an "\" like in
{/this\ is\ a\ directory}
Enjoy...
Posted: Thu Dec 01, 2005 7:15 pm
by cormullion
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!
Posted: Thu Dec 01, 2005 7:18 pm
by Lutz
... and you could shorten that to:
because format returns a string and can take other text besides format specs
Lutz
Posted: Fri Dec 02, 2005 8:15 am
by cormullion
Neat. Thanks.