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