【问题标题】:Error when redirecting stdout and stderr of powershell script重定向powershell脚本的stdout和stderr时出错
【发布时间】:2010-11-28 04:39:23
【问题描述】:

当 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

【问题讨论】:

  • 你的代码是什么样的?
  • 你从来没有接受我的回答,@ripper234
  • @x0n - 谢谢你提醒我,完成了。

标签: powershell stdout stderr


【解决方案1】:

我曾经在需要应用“GetItemChild”的目录中有几个硬链接联结,并收到与此问题相同的错误。

移除连接解决了问题。

【讨论】:

    【解决方案2】:

    Lee Holmes(powershell 团队的高级开发人员之一)在一篇博文中对此进行了介绍:

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

    这是 PowerShell v1.0 中的错误,发生在以下情况:

    • PowerShell 命令生成常规输出和错误输出
    • 您已使用 cmd.exe 将输出重定向到文件
    • 您已使用 cmd.exe 合并输出流和错误流

    有一个解决方法。

    -奥辛

    【讨论】:

    • 感谢您的文章。我尝试了两种解决方法(V1 和 V2 CTP),但都不起作用(“您不能在空值表达式上调用方法。”)
    • 你用的是什么版本?您没有在原始问题中说。
    • 嗯,我想我今天正在使用 V2,我想知道我是否也在 V3 中看到它。
    • @bernd_k 根据引用帖子的更新,它是为 Windows 8 排序的。我仍然无法相信我们将不得不在 V2 中再挣扎 10 年。 Grr.
    • 答案中的链接不再可用。解决方法是否在其他地方可用?
    猜你喜欢
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    • 2014-07-22
    • 2021-08-19
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 2012-10-08
    相关资源
    最近更新 更多