설명 할 수없는 다소 이상한 동작이 나타납니다.Write-Host의 이상한 부작용 Write-Host
텍스트 파일을 스트리밍하는 코드는 잘 보입니다. 나는 쓰기 호스트 줄을 REM 수면 경우
$journalPath = "$(Split-Path $($script:myInvocation.myCommand.path) -parent)\Journals"
$journals = Get-ChildItem $journalPath -filter "journal.*.txt"
Write-Host "Streaming"
foreach ($journal in $journals) {
$reader = [System.IO.File]::OpenText("$journalPath\$journal")
do {
$line = ($reader.ReadLine()).Trim()
if (-not ($line.StartsWith("'"))) {
Write-Host $line
}
} until ($line -eq $null)
$reader.Close()
}
그러나, 나는 라인 9
You cannot call a method on a null-valued expression.
의 $reader.ReadLine()
라인을 얻을. 왜 단순한 Write-Line이이 영향을 미칩니 까? 조건이 마지막에 발생하기 때문에 모든 (사후 소위) (소위 사전 검사) While() {…}
루프, Do {…} While()
뿐만 아니라 Do {…} Until()
루프는 달리
당신 "REM"그것을하면? Rem PowerShell 지시어는 없습니다. 우리에게 실패한 코드를 보여주십시오. –
매번이 예외를 받아야합니다. 내 생각에, 당신은 일을 끝내기 위해 코드를 기다릴 정도로 인내심이 없거나 파일을 길게 만들 수 있습니다. – PetSerAl
Rem in remark. 그래서 # Write-Host $ line – Gordon