lua-users home
lua-l archive

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


On 14-Jan-06, at 1:34 PM, Wim Couwenberg wrote:

 You can use ShellExecute. 
ShellExecute (and CreateProcess) create a *new* process (if file is an
executable that is.)  The posix exec family replaces the executable
image of the running process.  Very different models...

Also, the command parsing model is different. With exec(), you specify the argv array directly, so there is less need to worry about metacharacters (it is still possible that the utility will misinterpret an argument starting with a '-', though.) With ShellExecute and CreateProcess, you provide an unparsed command line, which is much riskier if you're constructing it from user input.
(In checking the MSDN Library, I also discovered this interesting 
tidbit:
  The Unicode version of this function, CreateProcessW,
  can modify the contents of this string. Therefore, this
  parameter cannot be a pointer to read-only memory (such
  as a const variable or a literal string) or the function
  could cause an access violation.

Or, in the case of a Lua binding, modify a Lua string with potentially disastrous consequences.
Leaving all that aside, though, wouldn't it be possible to implement a 
higher-level interface which did fork+exec on Unix and CreateProcess on 
Windows? That's a fairly commmon situation, anyway. CreateProcess seems 
to be able to specify stdin/stdout/stderr for the newly created 
process, which is what would normally done in the gap between the 
fork() and the exec() in Unix, so there is some hope for an interface 
which would work on both. Although I'm not sure how I would handle 
quoting of "shell" metacharacters.