1

In my package.json I have this entry :

"runMe": "set  AAA=3 && echo %AAA%"

which looks like that :

enter image description here

In general, I want to set env variable, and to read it at the next section...

I'm expecting to get in console: 3

But instead I get this %AAA% :

enter image description here

Question:

How can I get the echo to show 3? I prefer ( please) not to use third-party libraries.

0

1 Answer 1

1

For same section, try:


"runMe": "set  \"AAA=3\" && cmd /v/c echo %AAA%"
"runMe": "(set  \"AAA=3\") && cmd /v/c echo %AAA%"

rem :: or :: 

"runMe": "set  \"AAA=3\" && cmd /v/c echo !AAA!"
"runMe": "(set  \"AAA=3\") && cmd /v/c echo !AAA!"

for to read it at the next and same section, you need use global variable


"runMe": "setx  AAA 3 && for /f tokens^=3 %i in ('reg query HKCU\Environment ^|find aaa')do echo=%i"

For cmd command line, remove the scaping in \":

set  "AAA=3" && cmd /v/c echo %AAA%
(set  "AAA=3") && cmd /v/c echo %AAA%

rem :: or :: 

set  "AAA=3" && cmd /v/c echo !AAA!
(set  "AAA=3") && cmd /v/c echo !AAA!

Sorry my limited English

Sign up to request clarification or add additional context in comments.

4 Comments

btw ive managet to do it with SETLOCAL EnableDelayedExpansion in a batch file with !var! which causes it to be late binded
Direct in cmd : the SETLOCAL EnableDelayedExpansion == cmd /v --> cmd /v/c echo !AAA!"
btw - not it works in node but not in cmd. I mean why does this set \"AAA=3\" && cmd /v/c echo %AAA% doesnt work straight in cmd ?
\" scape coma for send the command to cmd.exe subsystem, this one in cmd: set "AAA=3" && cmd /v/c echo %AAA%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.