2012-07-09 231 views

回答

12

你得到另一個PowerShell進程在前者的情況下和腳本無法讀取當前會話定義的變量:

PS> $foo = 'bar' 
PS> 'Write-Host $foo'|Set-Content x.ps1 
PS> & powershell .\x.ps1 

PS> & .\x.ps1 
bar 
+0

感謝。錯誤處理也有差異嗎? – 2012-07-09 11:45:45

+1

@ColonelPanic:就像變量一樣,異常不會跨進程邊界。將'x.ps1'的內容更改爲'throw error',並比較'try {powershell.exe ./x.ps1; 「success?$ ?; $ LastExitCode」} catch {「caught $ _; success?$?; $ LastExitCode」}'和'try {./x.ps1; 「success?$ ?; $ LastExitCode」} catch {「caught $ _; success?$?; $ LastExitCode」}'。 – 2012-08-18 13:27:06