【问题标题】:Why don't Windows Shell (cmd.exe) builtin commands read from stdin?为什么不从标准输入读取 Windows Shell (cmd.exe) 内置命令?
【发布时间】:2023-03-18 12:55:01
【问题描述】:

为什么不从标准输入读取 Windows Shell (cmd.exe) 内置命令? (或者看起来)

例子:

echo bar | set /p foo=

【问题讨论】:

  • set /p 本身确实从标准输入读取。在该示例中,它只是通过管道输入。
  • 先看this answer,再看整个话题……

标签: batch-file cmd command-prompt windows-shell


【解决方案1】:

SET /P 确实从管道读取输入,但它没有任何好处,因为管道的两端都是在新的 cmd.exe 进程中执行的。因此,一旦管道子流程终止,新定义的变量就会丢失。

有关更多信息,请参阅 the selected answer 到 Stack Overflow 问题 - Why does delayed expansion fail when inside a piped block of code?

【讨论】:

    猜你喜欢
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多