passing format a list of strings

Q&A's, tips, howto's
Locked
two-
Posts: 4
Joined: Fri Feb 18, 2011 10:37 am

passing format a list of strings

Post 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?
»; }

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: passing format a list of strings

Post 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)))))

m i c h a e l
Posts: 394
Joined: Wed Apr 26, 2006 3:37 am
Location: Oregon, USA
Contact:

Re: passing format a list of strings

Post 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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: passing format a list of strings

Post 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...

Locked