두 개의 개별 텍스트 파일을 얻기 위해 PowerShell의 간단한 테스트 스크립트를 separate warning message from stdout/result에 작성하려고합니다. 하나는 경고 용이고 다른 하나는 표준 결과 용입니다. PowerShell Redirection입니다. ,경고 메시지를 stdout/powershell 리디렉션의 결과에서 분리하는 방법은 무엇입니까?
PowerShell.exe -Command "& '%~dp0output.ps1'" 3>warning.txt >results.txt
pause
하지만 내 문제는 warning.txt
입니다 완전히 비어 : 나는 명령 아래 사용하여 .BAT 파일을 사용하여 output.ps1
을 실행하기 위해 노력하고있어
Write-Output "This is result"
Write-Warning "This is warning"
가 :
은 여기 내 간단한 output.ps1
스크립트입니다 경고 및 결과 모두는 results.txt
에 기록됩니다.
This is result
WARNING: This is warning
나는 두 개의 파일로 경고 및 오류를 분리하는 PowerShell.exe -Command "& '%~dp0output.ps1'" 3>warning.txt >results.txt
에서 실종 무엇?
편집 : 표준 오류를보고 수정, 2>
가 노력하고 있습니다. 내가
PowerShell.exe -Command "& '%~dp0output.ps1'" 2>error.txt 3>warning.txt >results.txt
를 사용하여 2>error.txt
를 사용하여 별도의 파일에 표준 오류 리디렉션 나는 다음과 같은 방식으로 오류가 발생하는 output.ps1
을 수정하면
Write-Output "This is result"
Write-Warning "This is warning""
This will generate error because this is not a ps command.
이 같은 오류가 발생합니다 경우에도
파일로 예상 됨 error.txt
with results.txt
여기서 results.txt
은 경고와 stdout/result의 조합입니다. warning.txt
은 여전히 비어 있습니다. PowerShell 경고가 필터링되지 않고 별개의 파일로 제대로 리디렉션되지 않는 이유는 아직도 모르겠습니다.
error.txt :
this : The term 'this' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At C:\Users\Dell\Desktop\output.ps1:3 char:1
+ This will generate error because this is not a ps command.
+ ~~~~
+ CategoryInfo : ObjectNotFound: (this:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
RESULTS.TXT :
This is result
WARNING: This is warning
나는 윈도우 10와 PowerShell을 버전 5.1.14393.1358을 사용하고 있습니다. 당신이을 경고 PS1 파일 자세한, 을 실행하는 powershell.exe
를 사용하는 경우
'2> warning.txt'은 무엇입니까? –
powershell/cmd cant 리디렉션 경고 일 수 있습니까? 2> ..> 3>을 사용하여 리디렉션 할 수있는 오류는 공백 출력을 생성합니다. – user879
알다시피, cmd는 오류와 표준 스트림 만 있습니다. – Clijsters