Giter Club home page Giter Club logo

Comments (6)

phinney avatar phinney commented on June 15, 2024

This is a technique known as tunneling. See https://ss64.com/nt/syntax-functions.html for a description of what the technique is used for. Simply put, it's a way to do something with setlocal environments variables before endLocal throws out the values of those local environment variables. EndLocal environment variables don't get removed until the command line finishes.

from asar.

raccoon666666 avatar raccoon666666 commented on June 15, 2024

Thank you very much for your help.
This is the first time I have heard the concept of tunneling, and its implementation is very cool.
There is a section of code in asar.cmd that looks like this

call :func
goto :eof
:func
setlocal
set ret=1234
endlocal & goto #_undefined_# 2>nul || title %ret%

For goto #_undefined_# 2>nul,
It seems to have intentionally made an error and then executed the statement after ||
But according to tunneling, the last line is changed to
endlocal & title% ret%
Can also successfully obtain %ret%
So is goto #_undefined_# 2>nul completely redundant?

from asar.

phinney avatar phinney commented on June 15, 2024

That's right, the intentional error is done so that the code after the || is guaranteed to execute and that's of course where the local environment variable %ret% is used. When you see that technique used for the first time, it's certainly not obvious what's going on and it's certainly not explained in any online help documentation. By the way, nice question to ask since I think it'll be helpful to others who stumble here.

from asar.

phinney avatar phinney commented on June 15, 2024

Here's another link: https://ss64.com/nt/endlocal.html. It discusses the endlocal&set construct. It says that endlocal does not set or clear the errorlevel. Reading that, it sounds like "endlocal & title %ret%' would work without the "goto #undefined# 2>nul" line. The fact the endlocal does not set or clear the errorlevel adds a certain level of confusion as to how "endlocal& is implemented by the shell. By adding the redundant "goto" statement, it certainly removes some of that ambiguity. I'm not sure but this might be a way to quarentee that the code works in different shells (i.e. cmd, powershell and windows powershell, bash.) This is what I just hate about writing batch scripts, the code just isn't clear!

from asar.

malept avatar malept commented on June 15, 2024

FWIW the CMD file is provided by Node.js when you install asar, so the maintainers of this repo have no context as to its construction.

from asar.

raccoon666666 avatar raccoon666666 commented on June 15, 2024

This seems to be fixing the errorlevel to 1, possibly related to error handling

from asar.

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.