问题
Why don't Windows Shell (cmd.exe) built-in commands read from stdin? (or so it seems)
Example:
echo bar | set /p foo=
回答1:
SET /P does read the input from the pipe, but it doesn't do any good because both sides of the pipe are executed within new cmd.exe processes. So the newly defined variable is lost once the pipe sub-processes terminate.
For more information, see the selected answer to the Stack Overflow question - Why does delayed expansion fail when inside a piped block of code?
来源:https://stackoverflow.com/questions/37804188/why-dont-windows-shell-cmd-exe-builtin-commands-read-from-stdin