Why doesn't “set -P” work after a pipe?

后端 未结 4 1820
予麋鹿
予麋鹿 2021-02-14 09:13
C:\\>type c:\\output.txt
abcd
C:\\>type c:\\output.txt | set /p V1=

C:\\>set
... A bunch of junk, NOT seeing \"V1\"

What happened? According

4条回答
  •  梦毁少年i
    2021-02-14 09:45

    To add a brief example of how to confirm the other answers, you can immediately check the contents of the variable on the other side of the pipe using another set command IE:

    ECHO HELLO | (set /P hi= && set hi)

    Will output

    hi=HELLO

    But after execution the variables are destroyed : (, so a further 'set hi' will reveal:

    Environment variable hi not defined

提交回复
热议问题