set /p question...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
catalinnc
Posts: 39
Joined: 12 Jan 2015 11:56

set /p question...

#1 Post by catalinnc » 30 Apr 2017 13:18

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)?
_

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: set /p question...

#2 Post by aGerman » 30 Apr 2017 13:29

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

Post Reply