Windows 上的管道

lua-users home
wiki

由于 `popen()` 在标准 Windows 编译的 Lua 二进制文件中不受支持,因此以下代码将无法正常工作。
c = "''some shell command''" -- e.g. 'dir'
readfrom("|" .. c) -- this part will alway fail in standard Windows compiled binary
print(read("*a"))
但实际上有一种方法可以在 Windows 上启用对“管道”的支持(已在 win2k 和 Lua 4.0 上测试)

在 lua-l 上 David Burgess 写道

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")
POPEN,popen=_popen,pclose=_pclose

也尝试过使用 lcc for Windows。

您可以在 Compiler->Settings 面板中添加 POPEN 到 #defines 中。

不过,`_popen` 存在一个问题。Win32 API 文档指出,它仅在控制台应用程序中有效,因此如果您已将 Lua 嵌入到 Windows 应用程序中,则会遇到问题。但是,有一个补丁 [1],并且已在 SciTE 中进行了测试(它还提供了一个“静默”版本的 `os.execute`)。


RecentChanges · preferences
编辑 · 历史
最后编辑于 2004 年 7 月 2 日 下午 12:15 GMT (diff)