lua-users home
lua-l archive

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


On 30/11/2020 12:59, Roberto Ierusalimschy wrote:
>>> io.popen('lua.exe -e"print(string.char(49,26,50))"',
>> "rb"):read"*a":byte(1,-1)
>> stdin:1: bad argument #2 to 'popen' (invalid mode)
>> [...]
>>
>> Why does Lua 5.4 not allow me to read verbatim output of an external
>> Windows process?
> 
> According to the official documentation [1]:
...
> Note that the string "rb" is not in the list. :-)
> 
> More seriously, we really don't know the meaning of the above
> documentation, and therefore we don't know what to implement.
> (Maybe they mean "[rw][bt]?", but that is just speculation.)
...
> [1] https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/popen-wpopen?view=msvc-160

The linked page gives an example use with "rb". Seems pretty obvious
that you'd need to combine the text/binary modifier with the read/write
flags, just like (the better documented) fopen.

Worryingly, it also mentions:

> If used in a Windows program, the _popen function returns an invalid
> file pointer that causes the program to stop responding indefinitely.
> _popen works properly in a console application.

Which looks like an unpleasant catch for people embedding Lua in a
Windows app. The linked reference[1] looks ugly, like most win32 code.

As usual MS makes life far harder than it needs to be.

Scott

[1]
https://docs.microsoft.com/en-us/windows/win32/ProcThread/creating-a-child-process-with-redirected-input-and-output