Git Product home page Git Product logo

Comments (9)

chrisant996 avatar chrisant996 commented on September 24, 2024 1

This isn't related to Clink, it's just bugs in the batch script.

  1. See documentation for setlocal.
    • endlocal happens automatically at the end of the batch script, if there isn't an explicit endlocal in the script.
    • You could use the idiom endlocal & set PATH=%PATH% to end the setlocal scope, but also keep the value of %PATH%.
    • The idiom relies on the fact that CMD expands environment variables in the whole line before running any part of the line, so the %PATH% is expanded before the endlocal runs, but the set PATH={expanded value of %PATH%} runs after the endlocal.
  2. The set PATH at the end isn't reached because clink is a batch script; it's clink.bat.
    • The Clink executables are clink_x86.exe and clink_x64.exe, and the clink.bat script picks the right one to run based on whether the current cmd.exe is 32-bit or 64-bit.
    • Invoking a batch script from inside another batch script does not return to the original batch script. To return to the original script, use the call command. call clink inject.
    • Adding the call keyword makes the final set PATH show that the condabin directory is present, which demonstrates that the problems the script is encountering have nothing to do with Clink.

from clink.

chrisant996 avatar chrisant996 commented on September 24, 2024

Have you found the Usage section at the beginning of the documentation?

I think it answers the question.

Do you have questions about it?

clink inject --help

from clink.

davehorner avatar davehorner commented on September 24, 2024

it works perfectly find using just clink inject. maybe I need to slow down and read more docs. thank you for your fast reply.

from clink.

davehorner avatar davehorner commented on September 24, 2024

When I set path;

@echo off
setlocal enabledelayedexpansion

rem Define the directory to add to the PATH
set "directory=C:\Users\dhorner\anaconda3\condabin"

rem Check if the directory is already in the PATH
echo %PATH% | findstr /i /c:"%directory%" >nul
if errorlevel 1 (
    rem If not found, add the directory to the PATH
    set PATH
    set "PATH=%PATH%;%directory%"
    set PATH
) else (
    rem If found, do nothing
    echo Directory already exists in PATH.
)
endlocal

@echo off
rem set PATH=%PATH%;C:\Users\dhorner\anaconda3\condabin
clink inject
set PATH

set PATH does not include the variable that was added above the call to inject. if I move the inject above, I lose my subsequent commands and fall into the injected prompt. I will spend more time with the documentation. thank you

from clink.

chrisant996 avatar chrisant996 commented on September 24, 2024

Because of the endlocal which reverts all changes to the environment.

It's just a CMD scripting mistake and isn't related to Clink. 🙂

from clink.

davehorner avatar davehorner commented on September 24, 2024

I removed the endlocal. Thank you! However, I am still finding that the path is not coming thru.

@echo off
setlocal enabledelayedexpansion

rem Define the directory to add to the PATH
set "directory=C:\Users\dhorner\anaconda3\condabin"

rem Check if the directory is already in the PATH
echo %PATH% | findstr /i /c:"%directory%" >nul
if errorlevel 1 (
    rem If not found, add the directory to the PATH
    set PATH  <-- I verify its not there
    set "PATH=%PATH%;%directory%"
    set PATH    <-- I verify its there.
) else (
    rem If found, do nothing
    echo Directory already exists in PATH.
)

clink inject
set PATH  <-- doesn't run

then when run interactively from the injected prompt; it shows the original path.

from clink.

davehorner avatar davehorner commented on September 24, 2024

I didn't mean to suggest it was a bug in clink, just looking for a hand.

The idiom works great! It might be worth a note for others. maybe it's common knowledge.

call clink inject
endlocal & set PATH=%PATH% 

I appreciate your thoughtful response. Thank you.

from clink.

chrisant996 avatar chrisant996 commented on September 24, 2024

I didn't mean to suggest it was a bug in clink, just looking for a hand.

Starting a Discussion is more clear that it's just a request for general help that might be unrelated to the forum.

The idiom works great! It might be worth a note for others. maybe it's common knowledge.

Since it has nothing to do with Clink, it's hard to imagine where to mention it in the Clink documentation, and it's unclear how readers would find it when it was relevant to whatever they were doing.

Seems like the note belongs in a different forum, perhaps one about CMD scripting instead of about Clink.

from clink.

davehorner avatar davehorner commented on September 24, 2024

Sorry.

from clink.

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.