Pass environmental variables by reference from one to another batch file Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How can I pass arguments to a batch file?Is Java “pass-by-reference” or “pass-by-value”?Split long commands in multiple lines through Windows batch fileWindows batch files: .bat vs .cmd?Sleeping in a batch fileWhat's the difference between passing by reference vs. passing by value?Is JavaScript a pass-by-reference or pass-by-value language?How do I pass a variable by reference?How to sleep for 5 seconds in a batch file/cmd?Defining and using a variable in batch file

When was Kai Tak permanently closed to cargo service?

What do you call a floor made of glass so you can see through the floor?

また usage in a dictionary

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

Can anything be seen from the center of the Boötes void? How dark would it be?

For a new assistant professor in CS, how to build/manage a publication pipeline

How to compare two different files line by line in unix?

How can I use the Python library networkx from Mathematica?

How would a mousetrap for use in space work?

When a candle burns, why does the top of wick glow if bottom of flame is hottest?

Amount of permutations on an NxNxN Rubik's Cube

Do square wave exist?

Compare a given version number in the form major.minor.build.patch and see if one is less than the other

Does classifying an integer as a discrete log require it be part of a multiplicative group?

How to Make a Beautiful Stacked 3D Plot

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

What is homebrew?

How could we fake a moon landing now?

What is the longest distance a player character can jump in one leap?

Is grep documentation wrong?

What is the meaning of the simile “quick as silk”?

How do I make this wiring inside cabinet safer? (Pic)

Would "destroying" Wurmcoil Engine prevent its tokens from being created?

How to tell that you are a giant?



Pass environmental variables by reference from one to another batch file



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How can I pass arguments to a batch file?Is Java “pass-by-reference” or “pass-by-value”?Split long commands in multiple lines through Windows batch fileWindows batch files: .bat vs .cmd?Sleeping in a batch fileWhat's the difference between passing by reference vs. passing by value?Is JavaScript a pass-by-reference or pass-by-value language?How do I pass a variable by reference?How to sleep for 5 seconds in a batch file/cmd?Defining and using a variable in batch file



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm in this situation where I have one batch file which creates a bunch of variables, then starts (with start /w "file.batch") another batch file that uses and modifies the variables from the first batch file.



Now this works fine until the second file closes itself and returns to the first file, because the variables that were modified by the second file are not references to, but actually copy's of the original variables, meaning that they were no longer linked to the original variables. This renders the second script practically useless.



I know that call "file.batch" would run the second file in the same environment, which would fix the problem, but I want the second file to run in a separate window, which call "file.batch" doesn't.



Here's a quick demonstration of the problem:



File 1:



@echo off
set $var=0
echo before starting file 2: %$var%
start test02.bat
echo after starting file 2: %$var%
echo before calling file 2: %$var%
call test02.bat
echo after calling file 2: %$var%
pause&exit


File 2:



@echo off
echo inside file 2: %$var%
set $var=1
echo inside file 2: %$var%
exit /b 0


Output:



before starting file 2: 0


inside file 2: 0
inside file 2: 1


after starting file 2: 0
before calling file 2: 0
inside file 2: 0
inside file 2: 1
after calling file 2: 1









share|improve this question



















  • 3





    No. There is not. This is well known.

    – Noodles
    Mar 22 at 9:50











  • Well.. The only way would be to loop it to check if the second batch is running, if not, start it and only then echo stuff, but that is really alot of work compared to where you could just call the file.

    – Gerhard Barnard
    Mar 22 at 10:10












  • Thanks for the answers, I'll to do it by storing all the echo'd text in an array so when a part of the console has to be cleared, the text above it can be restored

    – Lenard van der Maas
    Mar 22 at 13:13

















0















I'm in this situation where I have one batch file which creates a bunch of variables, then starts (with start /w "file.batch") another batch file that uses and modifies the variables from the first batch file.



Now this works fine until the second file closes itself and returns to the first file, because the variables that were modified by the second file are not references to, but actually copy's of the original variables, meaning that they were no longer linked to the original variables. This renders the second script practically useless.



I know that call "file.batch" would run the second file in the same environment, which would fix the problem, but I want the second file to run in a separate window, which call "file.batch" doesn't.



Here's a quick demonstration of the problem:



File 1:



@echo off
set $var=0
echo before starting file 2: %$var%
start test02.bat
echo after starting file 2: %$var%
echo before calling file 2: %$var%
call test02.bat
echo after calling file 2: %$var%
pause&exit


File 2:



@echo off
echo inside file 2: %$var%
set $var=1
echo inside file 2: %$var%
exit /b 0


Output:



before starting file 2: 0


inside file 2: 0
inside file 2: 1


after starting file 2: 0
before calling file 2: 0
inside file 2: 0
inside file 2: 1
after calling file 2: 1









share|improve this question



















  • 3





    No. There is not. This is well known.

    – Noodles
    Mar 22 at 9:50











  • Well.. The only way would be to loop it to check if the second batch is running, if not, start it and only then echo stuff, but that is really alot of work compared to where you could just call the file.

    – Gerhard Barnard
    Mar 22 at 10:10












  • Thanks for the answers, I'll to do it by storing all the echo'd text in an array so when a part of the console has to be cleared, the text above it can be restored

    – Lenard van der Maas
    Mar 22 at 13:13













0












0








0








I'm in this situation where I have one batch file which creates a bunch of variables, then starts (with start /w "file.batch") another batch file that uses and modifies the variables from the first batch file.



Now this works fine until the second file closes itself and returns to the first file, because the variables that were modified by the second file are not references to, but actually copy's of the original variables, meaning that they were no longer linked to the original variables. This renders the second script practically useless.



I know that call "file.batch" would run the second file in the same environment, which would fix the problem, but I want the second file to run in a separate window, which call "file.batch" doesn't.



Here's a quick demonstration of the problem:



File 1:



@echo off
set $var=0
echo before starting file 2: %$var%
start test02.bat
echo after starting file 2: %$var%
echo before calling file 2: %$var%
call test02.bat
echo after calling file 2: %$var%
pause&exit


File 2:



@echo off
echo inside file 2: %$var%
set $var=1
echo inside file 2: %$var%
exit /b 0


Output:



before starting file 2: 0


inside file 2: 0
inside file 2: 1


after starting file 2: 0
before calling file 2: 0
inside file 2: 0
inside file 2: 1
after calling file 2: 1









share|improve this question
















I'm in this situation where I have one batch file which creates a bunch of variables, then starts (with start /w "file.batch") another batch file that uses and modifies the variables from the first batch file.



Now this works fine until the second file closes itself and returns to the first file, because the variables that were modified by the second file are not references to, but actually copy's of the original variables, meaning that they were no longer linked to the original variables. This renders the second script practically useless.



I know that call "file.batch" would run the second file in the same environment, which would fix the problem, but I want the second file to run in a separate window, which call "file.batch" doesn't.



Here's a quick demonstration of the problem:



File 1:



@echo off
set $var=0
echo before starting file 2: %$var%
start test02.bat
echo after starting file 2: %$var%
echo before calling file 2: %$var%
call test02.bat
echo after calling file 2: %$var%
pause&exit


File 2:



@echo off
echo inside file 2: %$var%
set $var=1
echo inside file 2: %$var%
exit /b 0


Output:



before starting file 2: 0


inside file 2: 0
inside file 2: 1


after starting file 2: 0
before calling file 2: 0
inside file 2: 0
inside file 2: 1
after calling file 2: 1






batch-file pass-by-reference






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 13:59









double-beep

3,13641532




3,13641532










asked Mar 22 at 9:37









Lenard van der MaasLenard van der Maas

457




457







  • 3





    No. There is not. This is well known.

    – Noodles
    Mar 22 at 9:50











  • Well.. The only way would be to loop it to check if the second batch is running, if not, start it and only then echo stuff, but that is really alot of work compared to where you could just call the file.

    – Gerhard Barnard
    Mar 22 at 10:10












  • Thanks for the answers, I'll to do it by storing all the echo'd text in an array so when a part of the console has to be cleared, the text above it can be restored

    – Lenard van der Maas
    Mar 22 at 13:13












  • 3





    No. There is not. This is well known.

    – Noodles
    Mar 22 at 9:50











  • Well.. The only way would be to loop it to check if the second batch is running, if not, start it and only then echo stuff, but that is really alot of work compared to where you could just call the file.

    – Gerhard Barnard
    Mar 22 at 10:10












  • Thanks for the answers, I'll to do it by storing all the echo'd text in an array so when a part of the console has to be cleared, the text above it can be restored

    – Lenard van der Maas
    Mar 22 at 13:13







3




3





No. There is not. This is well known.

– Noodles
Mar 22 at 9:50





No. There is not. This is well known.

– Noodles
Mar 22 at 9:50













Well.. The only way would be to loop it to check if the second batch is running, if not, start it and only then echo stuff, but that is really alot of work compared to where you could just call the file.

– Gerhard Barnard
Mar 22 at 10:10






Well.. The only way would be to loop it to check if the second batch is running, if not, start it and only then echo stuff, but that is really alot of work compared to where you could just call the file.

– Gerhard Barnard
Mar 22 at 10:10














Thanks for the answers, I'll to do it by storing all the echo'd text in an array so when a part of the console has to be cleared, the text above it can be restored

– Lenard van der Maas
Mar 22 at 13:13





Thanks for the answers, I'll to do it by storing all the echo'd text in an array so when a part of the console has to be cleared, the text above it can be restored

– Lenard van der Maas
Mar 22 at 13:13












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296685%2fpass-environmental-variables-by-reference-from-one-to-another-batch-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296685%2fpass-environmental-variables-by-reference-from-one-to-another-batch-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript