11

The script runs fine when stdout/stderr are not redirected.

When I add both stderr and stdout redirection, I getg the following error: How can I avoid it?

 % 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 
1
  • What does your code look like? Commented Sep 14, 2009 at 23:17

2 Answers 2

15

Lee Holmes (one of the senior developers on the powershell team) covers this here in a blog post:

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

This is bug in PowerShell v1.0, and happens when:

  • a PowerShell command generates both regular and error output
  • you have used cmd.exe to redirect the output to a file
  • you have used cmd.exe to merge the output and error streams

There is a workaround.

-Oisin

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the article. I tried both workaround (V1 and V2 CTP) and it doesn't work ("You cannot call a method on a null-valued expression.")
What version are you using? You don't say in your original question.
Well I think I'm using V2 today and I wonder if i see it in V3 too.
@bernd_k According to an update on the cited post, it's sorted for Windows 8. I still can't believe we're going to have to struggle on with it in V2 for another 10 years. Grr.
The link in the answer is no longer available. Is the workaround available anywhere else?
|
0

I once had several hard-linked junctions at directory that needed to have "GetItemChild" applied, and received the same error as this question.

Removing the junctions solved the problem.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.