在我的PowerShell腳本中,我收到了一個我不明白的錯誤。字符串替換PowerShell中的錯誤
的錯誤是:
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
Invalid regular expression pattern:
Menu "User" {
Button "EXDS" {
Walk_Right "EXDS"
}
}
.
At C:\test.ps1:7 char:18
+ ($output -replace <<<< $target) | Set-Content "usermenuTest2.4d.new"
+ CategoryInfo : InvalidOperation: (
Menu "User" {...do"
}
}
:String) [], RuntimeException
+ FullyQualifiedErrorId : InvalidRegularExpression
我的腳本文件讀入一個字符串(字符串A)然後嘗試從另一個文件中刪除String一個。這個錯誤意味着什麼,我該如何修復它?
我的代碼:
#set-executionpolicy Unrestricted -Force
#set-executionpolicy -scope LocalMachine -executionPolicy Unrestricted -force
$target=[IO.File]::ReadAllText(".\usermenuTest1.4d")
$output=[IO.File]::ReadAllText(".\usermenuTest2.4d")
($output -replace $target) | Set-Content "usermenuTest2.4d.new"
如果'$ target'或'$ output'是'$ null'否'InvalidRegularExpression' 異常將會是trhow。不是這個錯誤。 – 2013-05-03 11:07:39