lua-users home
lua-l archive

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


Hi,

Did you try with another command? e.g. "dir z:" (or another drive that doesn't exist)

To verify if it is just the exit command or all.

You can also run the exit command with the /B option to see if that makes a difference.

Reinder

On Sun, 6 May 2018, 08:45 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 didn't compile it on Windows myself. I downloaded the binary from "https://sourceforge.net/projects/luabinaries/files/5.3.4/Tools%20Executables/lua-5.3.4_Win32_bin.zip/download"

According to my tests, Linux and OSX are not affected by this.

The bug exists on Windows at least since Lua 5.2.1 (Very likely since 5.2.0, but I didn't test it)



Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
> print(os.execute("exit -1"))
nil     No error        0


Lua 5.2.1  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print(os.execute("exit -1"))
nil     No error        0


According to the Lua documentation

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.
When called without a command, os.execute returns a boolean that is true if a shell is available.


For the above test case. The first return value is "nil" as intended. However, the second return value "No error" is not specified in the documentation.
Furthermore, it is incorrect that the 3rd return value is 0. Non-zero value is expected.