windows windows子命令评估
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3408596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
windows subcommand evaluation
提问by mert
linux & unix shells can process subcommands like this.
linux 和 unix shell 可以处理这样的子命令。
$> command `subcommand`
does windows cmd shell similar feature?
windows cmd shell 有没有类似的功能?
回答by Michael Burr
You can get something similar using a variation of the for
command:
您可以使用for
命令的变体获得类似的结果:
FOR /F "usebackq tokens=*" %%a IN (`subcommand`) DO @command %%a
One big difference (besides being unintuitive and much uglier) is that it'll execute command
once for each line produced by subcommand
一个很大的区别(除了不直观和更难看)是它会command
为由subcommand
Note that inside a script file, the percent signs must be doubled up (use non-doubled percent signs if you have some reason to want to do this at the command line).
请注意,在脚本文件中,百分号必须加倍(如果您有理由想在命令行执行此操作,请使用非双倍百分号)。
回答by JaredReisinger
As a whole, no. The Windows Command Prompt really isn't much of a shell in that it doesn't provide much functionality of its own, independent from the commands that you can run. For example, in most Un*x shells, file globbing (matching foo.*
to a list of files) is handled by the shell itself. In Windows, every application sees the foo.*
from the command line and has to implement the file globbing on its own.
总的来说,没有。Windows 命令提示符实际上并不是一个外壳程序,因为它本身并没有提供很多独立于您可以运行的命令的功能。例如,在大多数 Un*x shell 中,文件通配(匹配foo.*
文件列表)由 shell 本身处理。在 Windows 中,每个应用程序都可以foo.*
从命令行看到 ,并且必须自己实现文件通配。
If you're moving down the road of trying to automate Windows, or want a more full-featured shell, you should consider using PowerShell, which doeslet you do sub-commands:
如果您正在尝试自动化 Windows,或者想要一个功能更全面的 shell,您应该考虑使用PowerShell,它可以让您执行子命令:
command (subcommand)
命令(子命令)