2012-01-30 13 views
9

Powershell 2.0 komut satırı:Aşağıdaki tutarsızlık bir açıklama arıyorum yönlendirme

aşağıdaki Powershell komut foo.ps1 Verilen: it Running

write-host "normal" 
write-error "error" 
write-host "yay" 

C:\>powershell .\foo.ps1 > out.txt 2>&1 ile

üretir:

normal 
C:\foo.ps1 : error 
At line:1 char:10 
+ .\foo.ps1 <<<< 
    + CategoryInfo   : NotSpecified: (:) [Write-Error], WriteErrorException 
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,foo.ps1 

Write-Host : The OS handle's position is not what FileStream expected. Do not use a handle simultaneously in one FileStream and in Win32 co 
de or another FileStream. This may cause data loss. 
At C:\foo.ps1:3 char:11 
+ write-host <<<< "yay" 
    + CategoryInfo   : NotSpecified: (:) [Write-Host], IOException 
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.WriteHostCommand 

Ama birlikte çalışan:

C:\>powershell .\foo.ps1 2>&1 > out.txt

(doğru) üretir:

normal 
C:\foo.ps1 : error 
At line:1 char:10 
+ .\foo.ps1 <<<< 
    + CategoryInfo   : NotSpecified: (:) [Write-Error], WriteErrorException 
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,foo.ps1 

yay 

Neredeyse ancak yönlendirme sırası Windows önemi olduğunu düşünerek içine tüm kendim çözüldü TechNet usage page for command redirection örnekler şekilde hataları yönlendirmeyi önceki dosya yeniden yönlendirme göstermektedir.

Birisi bana bunu açıklayabilir misiniz ?

C:\>powershell get-host 


Name    : ConsoleHost 
Version   : 2.0 
InstanceId  : 53c90e87-ded1-44f9-8e8d-6baaa1335420 
UI    : System.Management.Automation.Internal.Host.InternalHostUserInterface 
CurrentCulture : en-US 
CurrentUICulture : en-US 
PrivateData  : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy 
IsRunspacePushed : False 
Runspace   : System.Management.Automation.Runspaces.LocalRunspace 

ve yazmaya karşı çıktı kullanarak aynı sonucu üretir:

Referans için, bu konuda Server 2003 x64 SP2 üzerinde yapılıyor.

(Bu soru this çözümünde işime ilişkilidir.)

PowerShell 2.0 bir hata gibi görünüyor
+1

ben cevabını bilmiyorum ama o yaz-Sunucu tüm diğer Yaz davranırlar farklı muamele alır biliyorum. Ben şimdi veba gibi önlemek istiyorum. Testinizi Write-Output ile deneyin. Bahşiş için – EBGreen

+0

teşekkürler! maalesef aynı sonuç ortaya çıkıyor. –

+1

Write-Output ve Write-Host'un çok farklı amaçları vardır. Write-Host, PowerShell ana bilgisayarına bilgi (metin) yazar. Yaz-Çıktı ardından boru hattı girişini kabul eden bir komutla tarafından yakalanan ve işlenebilir PowerShell boru hattı, bir nesneyi yazar. Böyle bir komut kullanılmazsa, nesne çıkışı da ana bilgisayara verilir. –

cevap

1

. PowerShell 3.0 önizleme ile çoğaltmayı denedim ve şimdi beklendiği gibi çalışıyor.

+0

... daha mutlu bir cevabınız var mı? CTP yükseltme –

+0

, msft bildiririz –

İlgili konular