2009-09-14 59 views
11

當stdout/stderr沒有重定向時,腳本運行正常。重定向powershell腳本的stdout和stderr時出錯

當我添加stderr和stdout重定向時,我得到以下錯誤: 我該如何避免它?

% Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 

    0 19.4M 0  0 0  0  0  0 --:--:-- --:--:-- --:--:--  0 
81 19.4M 0  0 81 15.9M  0 54.5M --:--:-- --:--:-- --:--:-- 55.8M 
100 19.4M 0  0 100 19.4M  0 14.2M 0:00:01 0:00:01 --:--:-- 14.3M 
100 19.4M 0  0 100 19.4M  0 8428k 0:00:02 0:00:02 --:--:-- 8454k 
100 19.4M 0  0 100 19.4M  0 5924k 0:00:03 0:00:03 --:--:-- 5937k 
100 19.4M 0  0 100 19.4M  0 4567k 0:00:04 0:00:04 --:--:-- 4575k 
100 19.4M 0 50 100 19.4M  10 4291k 0:00:04 0:00:04 --:--:-- 835k 
out-lineoutput : The OS handle's position is not what FileStream expected. Do not use a handle simu 
ltaneously in one FileStream and in Win32 code or another FileStream. This may cause data loss. 
    + CategoryInfo   : NotSpecified: (:) [out-lineoutput], IOException 
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.OutLineOutputCom 
    mand 
+0

你的代碼是什麼樣的? – JasonMArcher 2009-09-14 23:17:34

+0

一些代碼調用CURL.exe – ripper234 2009-09-15 08:18:07

+0

你從來沒有接受我的答案,@ ripper234 – x0n 2013-05-01 20:04:09

回答

15

李霍姆斯(對PowerShell團隊的資深開發者之一)在一篇博客文章在這裏涵蓋了這一點:

http://www.leeholmes.com/blog/WorkaroundTheOSHandlesPositionIsNotWhatFileStreamExpected.aspx

這是錯誤PowerShell中V1.0,以及發生在:

  • 一個PowerShell命令生成規則和錯誤輸出
  • 您使用的cmd.exe重定向鄰本安輸出到文件
  • 您使用的cmd.exe合併輸出和錯誤流

有一種變通方法。

-Oisin

+0

感謝您的文章。我嘗試了兩種解決方法(V1和V2 CTP),但它不起作用(「您無法在空值表達式上調用方法。」) – ripper234 2009-09-14 16:49:26

+0

您使用的是哪個版本?你不是在你原來的問題中說。 – x0n 2009-09-15 17:16:57

+0

嗯,我想我今天使用的是V2,不知我是否也在V3中看到它。 – 2011-07-08 19:24:23

0

我曾經在目錄中需要有「GetItemChild」應用於幾個硬鏈接的路口,並收到了同樣的錯誤,因爲這問題。

去除連接點解決了問題。

相關問題