Powershell:如何捕获主机的输出
我正在使用 powershell 自动执行一些与 TFS 中签出/合并相关的任务。当我打电话时
tf get * /recurse
,我会看到一堆关于正在检出的文件的数据滚动。该命令生成的最后一行(假设成功)是告知签到号码的行。我想解析它,以便稍后在我的脚本中使用它。
我知道我可以做类似的事情
$getOutput = tf get * /recurse
,但随后输出被完全抑制,并且我希望该命令的输出实时滚动。我基本上想抓取刚刚发送到输出缓冲区的所有内容。
I am using powershell to automate some tasks related to checking out/merging in TFS. When I call
tf get * /recurse
I get a bunch of data scrolling by about the files that are getting checked out. The last line generated by this command (assuming its success) is one telling the checkin number. I would like to parse this out so it can be used later on in my script.
I know that I can do something like
$getOutput = tf get * /recurse
but then the output is suppressed entirely and I want the output of that command to be scrolled in realtime. I would basically like to grab everything that just got sent to the output buffer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的事情:
tf get * /recurse | tee-对象-变量 getOutput
Try something like this:
tf get * /recurse | tee-Object -Variable getOutput
PowerShell 2.0 中的 tee-object 允许您将结果通过管道传输到两个来源。如果将第二个源留空,结果将显示到控制台。
这会将目录列表写入控制台和文本文件。
The tee-object in PowerShell 2.0 allows you to pipe results to two sources. If you leave the second source empty, the results go to the console.
This will write the directory listing to both the console and a text file.