我基本上想这样做:
Get-Childitem -Recurse -filter "* *" -Force | foreach-object {
get-childitem $_ | select-object fullname |
Format-Table -HideTableHeaders -wrap |
out-string | cat $input
}
我认为这里的 Cat 是 powershell 的 get-content 的别名,但我在编写 bash 代码后经常使用它。我不认为这是问题所在。它给出了错误:
cat : The input object cannot be bound to any parameters for the command either because the command does not take
+ ... me | Format-Table -HideTableHeaders -wrap | out-string | cat $input }
尝试获取内容
:
Get-Childitem -Recurse -filter "* *" -Force | foreach-object {
get-childitem $_ | select-object fullname |
Format-Table -HideTableHeaders -wrap |
out-string | Get-Content $input
}
类似错误:
Get-Content : The input object cannot be bound to any parameters for the command either because the command does
not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
我还尝试删除out-string
。
寻找这个问题的答案是我如何到达out-string
的,但它不起作用。我很想知道如果可行的话如何在不分配变量的情况下做到这一点。
最佳答案
事实上,cat
是 Get-Content
的别名。在 Windows 上。
管道输入Get-Content
接受的唯一形式是表示文件路径的对象或字符串,然后输出其内容。
这不是Out-String
输出(它通常输出一个单多行字符串,在您的情况下是 Format-Table
生成的 for-display 格式输出的字符串表示形式)。
根据您的评论,您正在寻找如下内容:
Get-Childitem -Recurse -Directory -Filter "* *" -Force |
Get-ChildItem -File |
Get-Content
顺便说一句:automatic $input
variable仅在特定上下文中定义,并且不能按照您尝试的方式用作命令参数。具体来说,$input
表示当前整个范围的外部管道/标准输入输入,而不是流经给定管道的内容。
关于powershell - 如何将 powershell out-string 中的字符串作为参数传递给 get-content/cat (直接)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68944034/