2017-02-09 41 views
1

PowerShell參數是一個空字符串我想通過NodeJS參數中給出的字符串搜索文件。當PowerShell參數不是

param(
    [switch]$raw, 
    [string]$input 
) 

[string]$file = "*.log" 
if($raw) { $file = ".\raws\*.log" } 

Get-ChildItem -Recurse -Include $file | select-string $input 

的問題是,我得到了錯誤$input是空的: PowerShell says $input is empty.

我在做什麼錯?

+4

'$ input'是一個[自動變量](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/about/about_automatic_variables),你不應該使用它在您的代碼中的名稱。不知道這是爲什麼它突破,但它肯定是誤導。 – TessellatingHeckler

+0

那就是@TessellatingHeckler。非常感謝你。 – Farcrada

+0

[$ \ _和\ [參數(ValueFromPipeline = $ true)\]]之間的奇怪差異可能重複(http://stackoverflow.com/questions/13502949/strange-difference-between-and-parametervaluefrompipeline-true) –

回答

0

感謝@TessellatingHeckler指出$input是一個保留/自動變量,因此不能像這樣使用。