2012-08-29 2 views
2

현재 다음과 같이 실행되는 스크립트가 있습니다. . \ script.ps1 "param1" "param2"2> & 1 | tee -filePath buildlog.txt.ps1 스크립트 내의 PowerShell tee-object?

다음을 수행하는 방법을 찾을 수 없습니다. 콘솔과 파일 내에 캡슐화 된 파일 모두에 로깅. 사용하지 않는 로그 파일에 기록 할 경우

powershelltest.ps1

param([string]$paramOne, [string]$paramTwo) 

function DoWork() 
{ 
Write-Host '3' 
} 

function WriteLogFile() 
{ 
    DoWork 
# The following would not be captured by Start-Transcript & Stop-Transcript 
# program.exe .... 
Write-Host '4' 
} 

function CollectorFunction() 
{ 
    Write-Host '2' 
WriteLogFile; 
    Write-Host '5' 
} 

Write-Host '1' 
CollectorFunction 2>&1 | tee -filePath c:\log.foo 

답변

4

:. \ script.ps1 "PARAM1" "PARAM2"

여기에 그 일을하려고 시도한이다 Write-Host. Write-Output를 사용하거나 Write-Output 기본 예컨대 때문에 모든 Write-*을 사용하지 마십시오

Write-Output 'hello' > foo.txt 

가 동일합니다 :

'hello' > foo.txt 

Write-Output가 표준 출력 스트림에 출력을 전송합니다 (예 : 1). Write-Error을 사용하여 출력을 오류 스트림 (예 : 2)에 보냅니다. 이 두 스트림을 리디렉션 할 수 있습니다. Write-Host 출력 스트림을 모두 우회하여 호스트 UI에 직접적으로 씁니다.

The Windows PowerShell redirection operators use the following characters 
to represent each output type: 
    * All output 
    1 Success output 
    2 Errors 
    3 Warning messages 
    4 Verbose output 
    5 Debug messages 
1

내가 Start-Transcript을 사용합니다 :

PowerShell을 V3, 당신은 또한 다음과 같은 스트림을 리디렉션 할 수 있습니다. 유일한주의 사항은 표준 출력을 캡처하지 않으며 Write-Host의 출력 만 캡처한다는 것입니다. 그래서, 당신은 단지 Write-Host에 파이프 레거시 명령 줄 응용 프로그램에서 출력을 가지고 : 당신이 말한대로

Start-Transcript -Path C:\logs\mylog.log 
program.exe | Write-Host 
+0

시작 - 대본, 비 내장 명령의 표준 출력을 잡으려고하지 않는다; 하지만 버전 4.0에서 Powershell 명령의 표준 출력 (예 :'Write-Out '이 캡처 됨)을 캡처한다는 것을 알 수 있습니다 – jpaugh

관련 문제