问题 重定向PowerShell脚本的stdout和stderr时出错


当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

3210
2017-09-14 16:05


起源

你的代码是什么样的? - JasonMArcher
一些代码调用CURL.exe - ripper234
你从未接受我的回答,@ ripper234 - x0n
@ x0n - 谢谢你提醒我,完成了。 - ripper234


答案:


Lee Holmes(PowerShell团队的高级开发人员之一)在博客文章中介绍了这一点:

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

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

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

有一个解决方法。

-Oisin


15
2017-09-14 16:13



谢谢你的文章。我尝试了两种解决方法(V1和V2 CTP)并且它不起作用(“你不能在空值表达式上调用方法。”) - ripper234
你用的是什么版本?你原来的问题没有说。 - x0n
好吧,我想今天我正在使用V2,我想知道我是否也在V3中看到它。 - bernd_k
@bernd_k根据引用帖子的最新消息,它是针对Windows 8进行排序的。我仍然无法相信我们将不得不在V2中继续奋斗10年。格儿。 - Ruben Bartelink
答案中的链接不再可用。其他地方是否有可用的解决方法? - w128


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

拆除交叉点解决了这个问题。


0
2018-01-25 16:55