Comments (7)
Your question isn't clear to me? can you elaborate/rephrase please?
from penlight.
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.
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.
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.
So the official documentation of lua is not 100% accurate...
from penlight.
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.
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)
- Cleanup: drop or improve pl.url HOT 4
- Consider adding the built-in table methods to tablex? HOT 3
- Clone a function? HOT 8
- How about adding json decode and encode function HOT 4
- Error in pretty.write: invalid order function for sorting
- Bareword `warn` in compat.lua is a "strict" violation
- pl.Path.isdir Doesn't work correctly for Windows Base directory i.e. D:\\ (Lua 5.4.4) HOT 1
- Test suite failing on Arch Linux HOT 2
- lfs HOT 1
- stringx indent and dedent functions add an extra "\n" at the end of the string HOT 3
- lexer.cpp doesn't recognize #define without trailing newline HOT 2
- Can't use % as escape character in a template HOT 3
- Running the class's base function HOT 5
- Incorrect integer detection
- Consider implementing `cp` / `mv` via FFI HOT 2
- unexpected behavior for dir.clonetree HOT 1
- The `newline` option in the template module does not behave according to documentation HOT 4
- Fix link on luarocks HOT 3
- penlight 1.14 is rockspec_revision 1, but uses rockspec_revision 3 feature issues_url this breaks on luarocks-5.1 since it does not support rockspec 3 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from penlight.