2017-03-18 8 views
1

STDERRとSTDOUTを2つの別々のファイルにリダイレクトする必要があります。 powershell.exe OUPUTとERRORを別々のファイルにリダイレクトする方法はありますか?

は、私が試した次

  • だけエラーファイルにこの意志の出力誤差:

    powershell.exe -file c:\test.ps1 2> test.txt 
    
  • この意志の出力結果ファイルへのすべての出力:

    powershell.exe -file c:\test.ps1 2>&1> test.txt 
    

私の質問はhです私はSTDERRとSTDOUTをpowershell.exeを1回だけ実行することによって2つの別々のファイルにリダイレクトできますか?

答えて

2

複数のリダイレクトを指定できます。 Ex。

powershell.exe -file Sample.ps1 2>errors.txt 1>output.txt 

でSample.ps1

Write-Error "This is a critial error" 
Write-Output "This is output" 
"This is also output" 

ERRORS.TXT

C:\Users\frode\Desktop\Sample.ps1 : This is a critial error 
    + CategoryInfo   : NotSpecified: (:) [Write-Error], WriteErrorException 
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Untitled202.ps1 

OUTPUT.TXT

This is output 
This is also output 
+1

[関連](https://msdn.microsoft.com/ en-us/powershell/reference/3.0/microsoft.powershell.core /約/約about_redirection)を参照してください。 [関連](https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true)。 –

+0

ありがとう! Frode and Ansgar –

関連する問題