how to pass values from child process to parent cm

2020-07-20 15:41发布

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.

2条回答
冷血范
2楼-- · 2020-07-20 16:18

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.

查看更多
来,给爷笑一个
3楼-- · 2020-07-20 16:24

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.

查看更多
登录 后发表回答