lua-users home
lua-l archive

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




On Sun, May 6, 2018 at 4:58 AM, Kubo Takehiro <kubo@jiubao.org> wrote:
On Sun, May 6, 2018 at 3:44 PM, Haoqian He <hehaoqian@live.com> wrote:
> I have found a bug in the API "os.execute" when it runs a program that
> returns -1 on Lua 5.3.4 on Windows (Windows 10Home 64Bit, Version 10.0.16229
> Build 16229)

I guess that this issue will be fixed by the following patch.
(The patch is for lua 5.3.x. Replace LUA_USE_WINDOWS with LUA_WIN for Lua 5.2.)

https://gist.github.com/kubo/28a8a3c66858f6126ffc28f363c9e55f

Well, I have not tested it...
I tried applying your patch using get git apply with no success (though the working directory is not a git repo. I used --unsafe-paths). Can you recommend a patch tool on Windows or should I just apply it manually to test?  

C:\Users\russh\git\WinLua-VS2017\work\lua-5.3.4 [master ≡ +6 ~12 -1 !]> git apply --unsafe-paths .\patch-exit.patch
error: patch failed: work/lua-5.3.4/src/lauxlib.c:273
error: work/lua-5.3.4/src/lauxlib.c: patch does not apply
error: patch failed: work/lua-5.3.4/src/liolib.c:264
error: work/lua-5.3.4/src/liolib.c: patch does not apply
error: patch failed: work/lua-5.3.4/src/loslib.c:140
error: work/lua-5.3.4/src/loslib.c: patch does not apply

Thanks
Russ

> os.execute ([command])
> This function is equivalent to the ISO C function system. It passes command to be executed by an operating system shell. Its first result is true if > the command terminated successfully, or nil otherwise. After this first result the function returns a string plus a number, as follows:
> "exit": the command terminated normally; the following number is the exit status of the command.
> "signal": the command was terminated by a signal; the following number is the signal that terminated the command.

There is third case as far as I checked the lua source code.

text representation of errno: the system function itself fails; the
following number is the value of ISO C variable errno.

"No error" is the text representation of errno zero.
The patch checks errno in order not to go into the third case when the
ex 
ecuted command's exit code is -1.