Windows 上的管線

lua-users home
wiki

以下程式碼在標準的 Windows 編譯的 Lua 二進制檔案中會失敗,因為該平台不支援 popen()。
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

也嘗試了 Windows 的 lcc。

你可以在編譯器→設定面板的 #defines 中加入 POPEN。

不過,_popen 有個問題。Win32 API 說明文件中說明它只能在主控台應用程式中執行,所以如果你將 Lua 嵌入在 Windows 應用程式中,這會是個問題。不過,有一個補丁檔 [1] ,並且已在 SciTE 中測試過(這也提供了一個「quiet」版本的 os.execute)。


最近的變更 · 偏好設定
編輯 · 歷史記錄
最後編輯時間為 2004 年 7 月 2 日下午 6:15 GMT (diff)