lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, 28 Jan 2004, Reuben Thomas wrote:

> > os.execute and io.popen are scary functions.  When using them, you have
> > to be very certain about the contents of the strings being passed in.
> > I'm going to pick on your code, since you were brave enough to post it,
> > but this is an underlying problem many of us have run into.  Me, I ran
> > into it the hard way.  It would be nice if we could solve it just once.
>
> I'm not sure it's wise to try. Better is to do one of two things: in the
> case I've just outlined, it's better to use dirent functions (and more
> portable, OS-wise, although admittedly it means you need poslib).

Why's it in your std library then?

I think it's because sometimes it's useful to have a bare-Lua
implementation of these things, especially given that in a lot of
situations people don't have posix extensions built for their
platform.  Lua Cheia will help with this, but I'd really like there to
be an answer, if reasonable, for people who just download the upstream
C distribution and type make.

By the way, my execute("ls", "-aU", d) is broken as well, as it
doesn't handle when d starts with "-".  On modern Unix you can do

  execute("ls", "-aU", "--", d)

but on older machines you have to gsub(d, "^-", "./-") instead...

> In the case that you really want to use a complex command-line utility,
> like
>
> >    execute("find", d, "-type", "f", "-print", PIPE, "xargs", "wc"}
>
> it's better to use execl or execv. Again, poslib is required, but I think
> it's just not worth trying to work around the problems of using the shell.

It's not too hard to do both, with a common interface.

By the way, the thing I care about isn't stuff like /usr/bin/find,
it's

  execute("galeon", "--new-tab", url)

  execute("mipsel-linux-ld", "-T", LDSCRIPT, find_model'crti.o',
	find_lib'crtbeginS.o', "__jumptable.o", etc)

In that second case (mksnow for the Agenda toolchain) I can
install whatever version of Lua and extensions I want, though, so the
posix extension is probably a good idea.

Anyway, I'm offering to write the hokey /bin/sh version if we can
figure out the right API together. :-)

> This is the main objection to what I propose above. What can't you do
> conveniently with exec and glob?

Hm.  Now that I looked, between poslib and lposix, I don't see any way
of manipulating file descriptors.  Ugh.

> > On that note, specialized interpolation could do some good.
>
> Yes, this is a nice thing about Perl.
>
> > I don't know whether I think adding more syntax is a good idea or not.
>
> Debatable. I get along with .. and format in Lua without getting annoyed
> too often. OTOH, $ interpolation rocks.

I'm just trying to figure out what minimal support is needed at the
language level to let people write their own mechanisms....

Jay