lua-users home
lua-l archive

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


It was thus said that the Great Tomas Mudrunka once stated:
> Turns out that this is roughly equivalent to calling fsync() on fd:
> 
> os.execute("sync "..filename);
> 
> So i went with that. But the argument is not properly escaped, which is 
> fine in my case, since filename is hardcoded.
> 
> On the other hand it would be better if there was some way to pass 
> individual arguments in array without using shell to parse the 
> commandline.
> Eg.: something like this:
> 
> os.execute({"sync", "filename"});
> 
> lua can detect that table was passed rather than string. and bypass the 
> shell in that case.
> That would prevent need to have shell-specific (platform-specific) 
> escaping in lua...

  os.execute() is built around the C call system(), which the C standard
states (C99 and C11 are identical):

this about system():

	Synopsis
	     #include <stdlib.h>
	     int system(const char *string);

	Description

	If string is a null pointer, the system function determines whether
	the host environment has a command processor. If string is not a
	null pointer, the system function passes the string pointed to by
	string to that command processor to be executed in a manner which
	the implementation shall document; this might then cause the program
	calling system to behave in a non-conforming manner or to terminate.

	Returns

	If the argument is a null pointer, the system function returns
	nonzero only if a command processor is available. If the argument is
	not a null pointer, and the system function does return, it returns
	an implementation-defined value.

  So to bypass system(), you would have to again, implement operating system
specific (or "platform-specific") code.  While it would be possible to
implement what you want, the rabbit hole starts getting pretty deep.  For
instance, say you want to execute:

	somecommand files*

  Is Lua now responsible for expanding the file glob or not?  On Windows,
programs are expected to expand globs, while on POSIX systems, it's the
shell that does the expansion and not the program.  And globbing is
operating system specific as well.

  -spc