-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Way to use %errorlevel% in Lua scripts? #91
Comments
Nope. It's impossible. I did a lot of research into that already. It is exclusively an internal variable in CMD that is not exposed in any way at all, other than in the parser. |
Ok, I don't know how reliably this will work in practice, but I've hooked up an approach that's able to retrieve the value. But it's a bit invasive, so it's off by default. A new |
What do we mean by invasive here? Does that also mean that the prompt will become slower because of the hidden |
It's not about speed, it's about altering the actual stream of commands being issued to CMD. User enters three commands:
Clink actually runs:
It's two very different series of commands. To be clear -- Clink is not "running a command" like you'd expect Who knows what weird quirks it could run into. It's tempting to say nothing could go wrong because it's just a few For example, what if you press ^C during the I'm not saying there will be problems. I'm saying there is certainly potential for weird problems, and there's no way to predict. Invasive. |
Ah, understood. Thanks for taking the time to explain all this! Keeping in mind the potential for weird behaviour, does this also mean that in the future clink might provide a way to run any arbitrary command (just like |
First: It sounds like the question is "can Lua code call a function to run a command in the current session". There's no way to "call into CMD to run a command". That's all that Clink ever does! CMD calls into Clink code to "show a prompt and get input from the user". Clink returns a string to CMD, and CMD runs the string as a command. Repeat over and over until CMD exits. Second: It's possible to run any command in the current session by returning from Clink. But that's very messy. It would have to:
Notice that during steps 2 through 9 the prompt and input text are erased and are not visible. And if the command that effectively gets run during step 8 produces any stdout or stderr output then it won't just "flicker", there will be additional output visible. It's already possible to run anything in the current session ever since clink.onendedit() was added in v1.1.20. The only things missing from being to already do that today are (1) the ability to save/restore what the user had typed, (2) the ability to erase the prompt and input text, (3) the ability for the coroutine to get resumed, (4) the ability to prevent all Lua events from being sent during the procedure (mustn't let onbeginedit or onendedit event handlers run, and mustn't let any other Lua code run or a whole bunch of complicated nasty problems become easy to happen). So is it technically possible? Sure, I guess so. It seems like a very fragile and dangerous thing to do, and due to the coroutine requirement it's also going to be hard for a Lua programmer to get their code written correctly to be able to successfully do this. I think this should not be implemented. |
That's fair. Thanks again for all the details! |
I know ERRORLEVEL is not an environment variable, but an automatic variable.
os.getenv('ERRORLEVEL')
doesn't work for this reason.Is there a way to use it in Lua scripts, specifically for prompt? I'm trying to do something like this:
I couldn't find anything in the docs.
The text was updated successfully, but these errors were encountered: