Pipes On Windows

lua-users home

The following code will fail in a standard Windows compiled Lua binary, due to the fact that popen() is not supported on that platform.
c = "''some shell command''" -- e.g. 'dir'
readfrom("|" .. c) -- this part will alway fail in standard Windows compiled binary
But there actually is a way to enable support for 'pipes' on Windows (tested with win2k and Lua 4.0)

on the lua-l David Burgess wrote:

On VC6, Lua 4.0.1
from the project menu
Goto - "Project/Settings"
Tab - "C/C++"
Select "All configurations"
Edit field - "Preprocessor definitions"

and paste at the end of the existing string
(which should already have something like "WIN32,_CONSOLE,_MBCS")

Also tried with lcc for Windows.

You can add POPEN to the #defines on the Compiler->Settings panel.

There is an issue with _popen, however. The Win32 API documentation says that it will only work in console applications, so if you've embedded Lua in a Windows app, then that's a problem. However, there is a patch [1], and has been tested in SciTE (this also supplies a 'quiet' version of os.execute).

RecentChanges · preferences
edit · history
Last edited July 2, 2004 6:15 pm GMT (diff)