[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: io.popen(s, 'rb') ?
- From: Jon Mayo <jon.mayo@...>
- Date: Sat, 2 Oct 2010 11:15:13 -0700
On Sat, Oct 2, 2010 at 4:23 AM, Luiz Henrique de Figueiredo
>> local pipe = assert(io.popen('ls', 'r'))
>> succeeds, but
>> local pipe = assert(io.popen('ls', 'rb'))
>> 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
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.