Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass values from child process to parent cmd.exe shell?

Tags:

batch-file

cmd

I have a windows cmd.exe script that runs a child process and needs to collect the output from the child to set three variables. The child process does some work, and prints out three values.

How do I code the parent to collect the values printed out by child ?

I can make any amendments to the child process needed to do this, but the parent script must be written as a cmd.exe batch file.

like image 981
Martin Avatar asked Nov 29 '25 08:11

Martin


2 Answers

Is it acceptable that child process set environment variables? parent process should be able to pick that up.

child.bat

set VAR1=123
set VAR2=321

parent.bat

echo %VAR1%
echo %VAR2%
call child.bat
echo %VAR1%
echo %VAR2%

You can set environment variable from child program/script whatever language you are using - there are ways to set environment variables from them.

like image 168
mr.b Avatar answered Dec 01 '25 15:12

mr.b


The answer from mr.b happens to be correct is because, both batch script are running in the same cmd.exe process. Actually, child process could not write environment variables of parent process. Try other IPC methods.

like image 21
mr.c Avatar answered Dec 01 '25 15:12

mr.c



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!