Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Script file has 'OS Handle' error when run from script

Reply
 
Old 09-18-2007   #1 (permalink)
Jay
Guest


 
 

Script file has 'OS Handle' error when run from script

For my batch automation product, ActiveBatch, I've written a ps1 which is
called from a cmd file, and which runs fine when run from command prompt.
The script runs fine from a command prompt, but when I run it from within
ActiveBatch, it starts off ok but then fails with this message:

"Write-Host : The OS handle's position is not what FileStream expected. Do
not use a handle simultaneously in one FileStream and in Win32 code or
another FileStream. This may cause data loss."

The code it doesn't like is a write-host that documents the script's
progress. Interactively, messages appear on the console, but as it's being
run by ActiveBatch the messages are being written to a log file. The first 3
messages appear in the log file ok:

C:\XXExtract\XXExtract_Scripts>powershell .\XXExtract.ps1 "userid"
"password"
16:20:00: Initialising
16:20:00: Getting subs list
16:20:00: Processing XXXX sp
(return status = 0)

The point at which it's failing is when the '(return status = 0)' message is
generated, which I've checked by redirecting it: > NULL, whereupon the error
doesn't appear there, but then does appear for subsequent messages.
Actually, I'd like to keep all the output in the log file.

The message isn't documented anywhere I can find. Can anybody explain why it
might be getting upset and what I can do to get all my messages logged and a
happy and fulfilled script?

Jay




My System SpecsSystem Spec
Old 09-18-2007   #2 (permalink)
Oisin Grehan
Guest


 
 

Re: Script file has 'OS Handle' error when run from script

On Sep 18, 12:03 pm, "Jay" <j...@xxxxxx> wrote:
Quote:

> For my batch automation product, ActiveBatch, I've written a ps1 which is
> called from a cmd file, and which runs fine when run from command prompt.
> The script runs fine from a command prompt, but when I run it from within
> ActiveBatch, it starts off ok but then fails with this message:
>
> "Write-Host : The OS handle's position is not what FileStream expected. Do
> not use a handle simultaneously in one FileStream and in Win32 code or
> another FileStream. This may cause data loss."
>
> The code it doesn't like is a write-host that documents the script's
> progress. Interactively, messages appear on the console, but as it's being
> run by ActiveBatch the messages are being written to a log file. The first 3
> messages appear in the log file ok:
>
> C:\XXExtract\XXExtract_Scripts>powershell .\XXExtract.ps1 "userid"
> "password"
> 16:20:00: Initialising
> 16:20:00: Getting subs list
> 16:20:00: Processing XXXX sp
> (return status = 0)
>
> The point at which it's failing is when the '(return status = 0)' message is
> generated, which I've checked by redirecting it: > NULL, whereupon the error
> doesn't appear there, but then does appear for subsequent messages.
> Actually, I'd like to keep all the output in the log file.
>
> The message isn't documented anywhere I can find. Can anybody explain why it
> might be getting upset and what I can do to get all my messages logged and a
> happy and fulfilled script?
>
> Jay
In powershell v1, write-host messages cannot be redirected (or
captured in any way) to a file. Additionally, I take it you meant ">
nul" (one L, not two?)

If this annoys you as much as I think it probably will (you're not
alone), you can vote for it (to be fixed for v2) here:

https://connect.microsoft.com/feedba...7055&SiteID=99

- Oisin

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Converting a BAT script into a PowerShell Script PowerShell
Logon Script Causing Laptops To Hang - Problems in script? VB Script
problem passing args to script 'There is no script engine for file extenstion' VB Script
Include another script, keep variables in included script? PowerShell
Can you drag-n-drop a file on top of a PS script to run the script? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46