Page 1 of 1

passing format a list of strings

Posted: Mon Feb 21, 2011 9:16 am
by two-
I have a function run-sh defined as so:

Code: Select all

(define (run-sh sTr) (exec (format {'%s'} sTr)))
run-sh is a kind of basic function that takes input sTr - the shell command.
newLISP can call it like this:

Code: Select all

(run-sh {ls -a -l})
or, so i wish. The problem is this is my error message:

Code: Select all

sh: ls -a -l: command not found
I know you're probably wondering 'why not use (exec ...?' but, let's say, if I wanted to do this, how can i pass a list of strings to run-sh such that the first string is the command name, and have newLISP pass the remaining strings as the command's arguments?
ยป; }

Re: passing format a list of strings

Posted: Mon Feb 21, 2011 11:07 am
by cormullion
The single quotes are confusing the shell.

Code: Select all

(define (run-sh sTr) (exec (format {%s} sTr)))
   (run-sh {ls -a -l})
This is possible:

Code: Select all

(define (run-sh) 
    (exec (format {%s} (join (args)))))

Re: passing format a list of strings

Posted: Mon Feb 21, 2011 10:38 pm
by m i c h a e l
cormullion?!

I've missed you! It's not the same place around here without you, but I certainly understand if you have other priorities now. I myself am not here as much as I'd like to be anymore :-(

Are you trying out other languages, or have you given up on programming altogether? Either way, it's good to hear from you again.

m i c h a e l

Re: passing format a list of strings

Posted: Tue Feb 22, 2011 10:06 am
by cormullion
Hi michael - Yes, I just pop in occasionally to catch up on the excitement :) ... I don't have much time to do anything worth sharing...