将PowerShell脚本的标准输出和错误输出重定向时出现错误

11

在未重定向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

你的代码是什么样子的? - JasonMArcher
2个回答

15

感谢您的文章。我尝试了两种解决方法(V1和V2 CTP),但都没有成功(“您无法在空值表达式上调用方法。”)。 - ripper234
你在使用什么版本?在你的原始问题中没有提到。 - x0n
我想今天我正在使用V2,我想知道它是否也在V3中出现了。 - bernd_k
2
根据引用帖子的更新,Windows 8已经解决了这个问题。我仍然无法相信我们将不得不在V2中继续努力10年。Grr。 - Ruben Bartelink
答案中的链接已不再可用。是否有其他地方可以找到解决方法? - w128
博客文章的新URL:http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-expected/ - w128

0

我曾经在一个目录下有几个硬链接的接口,需要应用"GetItemChild"函数,结果遇到了与这个问题相同的错误。

删除这些接口解决了问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接