lua-users home
lua-l archive

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


David Given <dg@cowlark.com> writes:

> I have an interesting problem involving one of my projects on Unix.
>
> The reasons why are complicated, but my project boils down to needing to run a 
> Lua script, passed in on stdin, while giving the script arguments. According 
> to the documentation, this should work:
>
> cat script.lua | lua - -- argument1 argument2 argument3
>
> However, what actually happens is that script.lua gets executed with arg as 
> nil, and then when it terminates, the interpreter tries to load argument1 and 
> fails.
>
> Looking at lua.c, I see that the handle_argv() function only builds the arg 
> table *after* it's finished processing all the options. Because - is 
> considered an option, any script that gets executed as part of its execution 
> doesn't get any arguments...
>
> On Linux I can work around this by using /dev/stdin as an input filename, and 
> for now I'm going to hack my version of lua.c so that this will work on other 
> systems, but I reckon this is at least a bug --- definitely a misfeature.
>

why don't you want to save data from stdin into work file?

cat >/tmp/stdin.$$
lua /tmp/stdin.$$ argument1 argument2 argument3
rm /tmp/stdin.$$

this way suits for any systems.

-- 
Yours sincerely, Eugeny.
Doctor Web, Ltd. http://www.drweb.com