![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Select-String FileShare.ReadWrite How come powershell cannot open files that are in use even if they have the share flag specified? Below are exact details of the error I am getting. Please let me know if there is a way to get around this error. Thanks. ----- The log file I am try to parse is already opened in another application using the below line of code in c#. FileStream fsLog = new FileStream(@"C:\logfiles\20080609system.log", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); The below commands show the error I get when trying to open it in powershell. PS C:\logfiles> Select-String -pattern "1" 20080609system.log Select-String : The file can not be read: C:\logfiles\20080609system.log At line:1 char:14 + Select-String <<<< -pattern "1" 20080609system.log PS C:\logfiles> $error[0] | format-list * -force Exception : System.ArgumentException: The file can not be read: C:\logfiles\ 20080609system.log ---> System.IO.IOException: The process cannot access the file 'C:\ logfiles\20080609system.log' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Select-String FileShare.ReadWrite It may well be that Select-String doesn't honour the FileShare.ReadWrite and wants exclusive access to the file -- Richard Siddaway All scripts are supplied "as is" and with no warranty PowerShell MVP Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Bob Bins" wrote: Quote: > How come powershell cannot open files that are in use even if they have the > share flag specified? Below are exact details of the error I am getting. > > Please let me know if there is a way to get around this error. > > Thanks. > ----- > > > The log file I am try to parse is already opened in another application > using the below line of code in c#. > > FileStream fsLog = new FileStream(@"C:\logfiles\20080609system.log", > FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); > > The below commands show the error I get when trying to open it in > powershell. > > PS C:\logfiles> Select-String -pattern "1" 20080609system.log > Select-String : The file can not be read: C:\logfiles\20080609system.log > At line:1 char:14 > + Select-String <<<< -pattern "1" 20080609system.log > PS C:\logfiles> $error[0] | format-list * -force > > > Exception : System.ArgumentException: The file can not be read: > C:\logfiles\ > 20080609system.log ---> System.IO.IOException: The > process cannot access the file 'C:\ > logfiles\20080609system.log' because it is being > used by another process. > at System.IO.__Error.WinIOError(Int32 errorCode, > String maybeFullPath) > > > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Select-String FileShare.ReadWrite That's exactly what I needed. Thank you. "Shay Levi" <no@xxxxxx> wrote in message news:95d808932fe2f8ca987891454730@xxxxxx Quote: > > You can workaround it: > > > get-content C:\logfiles\20080609system.log | select-string -pattern > "yourPattern" > > > > --- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com > Quote: >> How come powershell cannot open files that are in use even if they >> have the share flag specified? Below are exact details of the error I >> am getting. >> >> Please let me know if there is a way to get around this error. >> >> Thanks. >> ----- >> The log file I am try to parse is already opened in another >> application using the below line of code in c#. >> >> FileStream fsLog = new FileStream(@"C:\logfiles\20080609system.log", >> FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); >> >> The below commands show the error I get when trying to open it in >> powershell. >> >> PS C:\logfiles> Select-String -pattern "1" 20080609system.log >> Select-String : The file can not be read: >> C:\logfiles\20080609system.log >> At line:1 char:14 >> + Select-String <<<< -pattern "1" 20080609system.log >> PS C:\logfiles> $error[0] | format-list * -force >> Exception : System.ArgumentException: The file can not be >> read: >> C:\logfiles\ >> 20080609system.log ---> System.IO.IOException: >> The >> process cannot access the file 'C:\ >> logfiles\20080609system.log' because it is >> being >> used by another process. >> at System.IO.__Error.WinIOError(Int32 >> errorCode, >> String maybeFullPath) > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Select-String FileShare.ReadWrite You can workaround it: get-content C:\logfiles\20080609system.log | select-string -pattern "yourPattern" --- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > How come powershell cannot open files that are in use even if they > have the share flag specified? Below are exact details of the error I > am getting. > > Please let me know if there is a way to get around this error. > > Thanks. > ----- > The log file I am try to parse is already opened in another > application using the below line of code in c#. > > FileStream fsLog = new FileStream(@"C:\logfiles\20080609system.log", > FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); > > The below commands show the error I get when trying to open it in > powershell. > > PS C:\logfiles> Select-String -pattern "1" 20080609system.log > Select-String : The file can not be read: > C:\logfiles\20080609system.log > At line:1 char:14 > + Select-String <<<< -pattern "1" 20080609system.log > PS C:\logfiles> $error[0] | format-list * -force > Exception : System.ArgumentException: The file can not be > read: > C:\logfiles\ > 20080609system.log ---> System.IO.IOException: > The > process cannot access the file 'C:\ > logfiles\20080609system.log' because it is > being > used by another process. > at System.IO.__Error.WinIOError(Int32 > errorCode, > String maybeFullPath) |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| can I pipe to select-string? | PowerShell | |||
| problems with $var | select-string -pattern $string -q | PowerShell | |||
| Re: select-string exceptions | PowerShell | |||
| Re: select-string exceptions | PowerShell | |||
| select-string exceptions | PowerShell | |||