管道到 Out-GridView 和 Out-File 有不同的行? [英] Pipe to Out-GridView and Out-File got different rows?

查看:59
本文介绍了管道到 Out-GridView 和 Out-File 有不同的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下命令只返回一行(忽略参数-Context 10.)

The following command returns only one row (the parameter -Context 10 is ignored.)

select-string -path file.txt -pattern "..." -Context 10 | Out-GridView

但是,以下命令会创建一个包含所有行的文件.

However, the following command create a file with all the lines.

select-string -path file.txt -pattern "..." -Context 10 | Out-File file2

为什么会有区别?

推荐答案

这是因为 Out-Gridview 消耗了 Select-String<的整个 MatchInfo 对象/code> 输出,并将该对象的所有属性显示为列.Out-File 另一方面,在将其输出到文件之前,基本上对所有内容执行 ToString() 方法,并且在将其转换为字符串时对于这种对象它输出行,以及上下文行.如果您希望 Out-GridView 做到这一点,您必须通过管道传输到 Out-String,然后再传输到 Out-GridView.

This is because Out-Gridview consumes the entire MatchInfo object that Select-String outputs, and displays all of the properties of that object as columns. Out-File on the other hand basically performs the ToString() method on everything before it outputs it to a file, and for that kind of object when it converts to a string it outputs the line, and the context lines as well. If you want Out-GridView to do that you will have to pipe to Out-String and then to Out-Gridview.

这篇关于管道到 Out-GridView 和 Out-File 有不同的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆