1

Why don't Windows Shell (cmd.exe) built-in commands read from stdin? (or so it seems)

Example:

echo bar | set /p foo=
nawK
  • 693
  • 1
  • 7
  • 13
  • 1
    `set /p` by itself _does_ read from stdin. It's just getting piped input in that example. – SomethingDark Jun 14 '16 at 11:34
  • 1
    See [this answer](http://stackoverflow.com/questions/8192318/why-does-delayed-expansion-fail-when-inside-a-piped-block-of-code/8193124#8193124) first and then, the whole topic... – Aacini Jun 14 '16 at 13:28

1 Answers1

3

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?

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390