lua-users home
lua-l archive

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


On Sat, Oct 2, 2010 at 4:23 AM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>>   local pipe = assert(io.popen('ls', 'r'))
>> succeeds, but
>>   local pipe = assert(io.popen('ls', 'rb'))
>> gives:
>>   lua: t:2: ls: Invalid argument
>> (It doesn't complain about 'rb', it complains about 'ls' !?)
>
> The message "Invalid argument" is coming from the OS.
>
>> The manpage I found says:
>>   The mode string can also have a 'b' at the end, which is needed
>>   in some systems to open the file in binary mode. This string
>>   is exactly what is used in the standard C function fopen.
>
> Not what POSIX says: http://www.opengroup.org/onlinepubs/009695399/functions/popen.html
>
>

On POSIX systems you wouldn't use 'b'. But on Windows
(http://msdn.microsoft.com/en-us/library/96ayss4b%28VS.80%29.aspx )
the 'b' is required for a binary mode.

In my opinion Lua programs shouldn't have to care if it is on Windows
or POSIX, so I'd call this a bug in the io library for not
interpreting the mode flags. Or alternatively I would express this as,
you can't use binary data with io.popen in a portable way because you
can't reliably pass 'b', which Windows needs.

- Jon