6
& powershell .\other.ps1
と& .\other.ps1
の動作がどのように違うのですか?PowershellがPowershellスクリプトを呼び出す
編集:特に、other.ps1
にエラーがある場合、それらはどのように異なるのですか?
& powershell .\other.ps1
と& .\other.ps1
の動作がどのように違うのですか?PowershellがPowershellスクリプトを呼び出す
編集:特に、other.ps1
にエラーがある場合、それらはどのように異なるのですか?
あなたは前者の場合には、別のPowerShellプロセスを取得し、スクリプトがあなたの現在のセッションで定義された変数を読み取ることができません。
PS> $foo = 'bar'
PS> 'Write-Host $foo'|Set-Content x.ps1
PS> & powershell .\x.ps1
PS> & .\x.ps1
bar
感謝を。エラー処理にも違いがありますか? –
@ColonelPanic:変数と同様、例外はプロセスの境界を越えません。 'x.ps1'の内容を' throw error'に変更し、 'try {powershell.exe ./x.ps1; "成功?$ ?; LastExitCode"} catch {"$ _;成功?$?; $ LastExitCode"} 'と' try {./x.ps1; "成功?$ ?; LastExitCode"} catch {"catch $ _; success?$ ?; $ LastExitCode"} '。 –