GithubHelp home page GithubHelp logo

Comments (7)

Tieske avatar Tieske commented on July 30, 2024

Your question isn't clear to me? can you elaborate/rephrase please?

from penlight.

jlaurens avatar jlaurens commented on July 30, 2024

compat.execute reads

function compat.execute(cmd)
    local res1,res2,res3 = os.execute(cmd)
    if res2 == "No error" and res3 == 0 and compat.is_windows then
...

The test condition only concerns lua 5.2+ because in lua 5.1 both res2 and res3 are nil. In lua 5.2-4

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.

and res2 is either 'exit' or 'signal'. So, if we stick to the official Lua online documentation, the test condition is never met.

from penlight.

Tieske avatar Tieske commented on July 30, 2024

this is Windows specifc. Windows can return errors as negative number I think, or something. That is why Lua may report an error from os.execute, but then the error message it gets from the cruntime is passed along. In the case where the exit code hits this special case, then Lua will report an error, but the error message returned by Lua will be "No error" (from the runtime). So Lua treats it as an error, but it wasn't.

You can check the Lua mailing archives on some discussion on this. iirc it was finally fixed in Lua 5.4.x

So now I recall; Lua code checks for a -1 return value of the C call. But in Windows -1 can be valid exitcodes. So the proper thing to do is clear errno, and check that afterwards. Because just checking for -1 will match the case of an error as well as a -1 exit code (but not an error).

from penlight.

Tieske avatar Tieske commented on July 30, 2024

see: https://www.lua-users.org/lists/lua-l/2018-11/msg00321.html
and follow up: https://www.lua-users.org/lists/lua-l/2019-01/msg00125.html

from penlight.

jlaurens avatar jlaurens commented on July 30, 2024

So the official documentation of lua is not 100% accurate...

from penlight.

Tieske avatar Tieske commented on July 30, 2024

Those docs are typically very accurate. But especially older versions of Lua didn't take that into account. 5.4 now does the right thing, but 5.1/2/3 do not, hence those special cases.

from penlight.

jlaurens avatar jlaurens commented on July 30, 2024

I came to that question in the very particular situation of luatex that embeds lua 5.3 except for os.execute that returns 5.1 like output. Of course, this can cause problems with penlight. Hence the documentation must be very clean in the luatex ecosystem as far as windows is concerned of course. But all this is out of purpose here.
Thanks.

from penlight.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.