Page 1 of 1

set /p question...

Posted: 30 Apr 2017 13:18
by catalinnc
this is the batch (inspired by one of the posts by Aacini)...

Code: Select all

@echo off

setlocal disabledelayedexpansion

echo(test | (set /P "_line=" & set _)

set _

endlocal

pause


this is the result (win xp sp2)...

Code: Select all

_line=test
Environment variable _ not defined
Press any key to continue . . .


how comes that the variable %_line% vanishes outside the brackets?

how can i retain it outside the brackets (beside echoing it to a file)?
_

Re: set /p question...

Posted: 30 Apr 2017 13:29
by aGerman
Basically this has nothing to do with the brackets. The reason is that every side of a pipe is executed in a newly created cmd.exe process. The new processes inherits the environment from the parent batch process. But that doesn't work vice versa, which means that child processes can't change the environment of their parent.

Steffen