2012-04-20 64 views
0

在我的PowerShell腳本中,我想使用一個工具的輸出,如git在Powershell管道中使用命令行工具的控制檯輸出

例如,在命令行

 
git status 

回報

 
# On branch master 
nothing to commit (working directory clean) 

現在我想在下面的管道命令使用此輸出:

 
git status | $_.Contains("nothing to commit") 

但我得到的錯誤

Expressions are only allowed as the first element of a pipeline.

我在做什麼錯?

回答

2
$msg = [string](git status) | where { $_.Contains("nothing to commit") } 
2

您可以使用select-string

git status | select-string "nothing to commit"