2009-09-14 161 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”应用于几个硬链接的路口,并收到了同样的错误,因为这问题。

去除连接点解决了问题。