![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Quiting a ps1 script when an error occurs I've got a PSH prompt open, and have called a .ps1 script. It contains an error. It seemingly loops forever, and if I Ctrl-C it stops. That's fine and all, but the script seems to hold on to files it reads/writes: PS C:\> gc 1.csv|select-object -first 1 Get-Content : The process cannot access the file 'C:\1.csv' because it is being used by another process. At line:1 char:3 + gc <<<< 1.csv|select-object -first 1 Only way I know out is to kill the PSH prompt and open a new one. There must be a better way? Marco |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Quiting a ps1 script when an error occurs Marco Shaw wrote: > I've got a PSH prompt open, and have called a .ps1 script. It contains an > error. > > It seemingly loops forever, and if I Ctrl-C it stops. > > That's fine and all, but the script seems to hold on to files it > reads/writes: > PS C:\> gc 1.csv|select-object -first 1 > Get-Content : The process cannot access the file 'C:\1.csv' because it is > being used by another process. > At line:1 char:3 > + gc <<<< 1.csv|select-object -first 1 > > Only way I know out is to kill the PSH prompt and open a new one. > > There must be a better way? > > Marco Mmmm... that seems like a pretty bad bug. Terminated pipelines should be terminated, not still holding open file handles. I guess it's a bit trickier given that there's no automatic cleanup for threads, only processes, and PowerShell runs pipelines in threads. |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Quiting a ps1 script when an error occurs Hi Marco, > That's fine and all, but the script seems to hold on to files it > reads/writes: > PS C:\> gc 1.csv|select-object -first 1 > Get-Content : The process cannot access the file 'C:\1.csv' because it is > being used by another process. > At line:1 char:3 > + gc <<<< 1.csv|select-object -first 1 > > Only way I know out is to kill the PSH prompt and open a new one. What happens when you enter PS C:\> [GC]::Collect(); [GC]::WaitForPendingFinalizers() a few times? Are the files still locked? cu Max |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Quiting a ps1 script when an error occurs On Nov 9, 5:39 am, Maximilian Hänel <ngS...@smjh.de> wrote: > Hi Marco, > > > That's fine and all, but the script seems to hold on to files it > > reads/writes: > > PS C:\> gc 1.csv|select-object -first 1 > > Get-Content : The process cannot access the file 'C:\1.csv' because it is > > being used by another process. > > At line:1 char:3 > > + gc <<<< 1.csv|select-object -first 1 > > > Only way I know out is to kill the PSH prompt and open a new one.What happens when you enter > > PS C:\> [GC]::Collect(); [GC]::WaitForPendingFinalizers() > > a few times? Are the files still locked? This works for me if I do something like: > (gi "foo.txt").Open([System.IO.FileMode]"Open") CanRead : True [... goodness ...] > (gi "foo.txt").Open([System.IO.FileMode]"Open") Exception calling "Open" with "1" argument(s): "The process cannot access the file 'C:\users\jam\repos\foo.txt' because it is being used by another process." [... badness ...] > [GC]::Collect(); [GC]::WaitForPendingFinalizers() > $f.open([System.IO.FileMode]"Open") CanRead : True [... goodness ...] |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Quiting a ps1 script when an error occurs > What happens when you enter > > PS C:\> [GC]::Collect(); [GC]::WaitForPendingFinalizers() > > a few times? Are the files still locked? I fixed my problem, so there's no lock for me to test anymore. I'll research what you're telling me above. Looks like something useful in case I get in trouble again. |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: Quiting a ps1 script when an error occurs "Jason Mobarak" <jason.mobarak@gmail.com> wrote in message news:1163118105.449805.314680@m7g2000cwm.googlegroups.com... On Nov 9, 5:39 am, Maximilian Hänel <ngS...@smjh.de> wrote: > PS C:\> [GC]::Collect(); [GC]::WaitForPendingFinalizers() That's a good line to be remembered for, Jason. ![]() |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How To Delete Items When Unknown Error Occurs | Kayla | Vista mail | 0 | 06-14-2008 11:48 AM |
| Cannot Upgrade to Vista - An Error Occurs (Xp SP3) | DsurioN | Vista installation & setup | 6 | 04-27-2008 04:30 PM |
| Script file has 'OS Handle' error when run from script | Jay | PowerShell | 1 | 09-18-2007 07:06 PM |
| When trying to un-junk mails Windows Mail has decied is Junk an error occurs | Rasmus Bertelsen | Vista mail | 2 | 07-08-2006 04:41 AM |
| Password does not work when idle-time lockout occurs | wineward | Vista account administration | 0 | 06-22-2006 09:07 AM |