I am trying to access, by means of a powershell code inserted in a bat, to a log file created by another program but it gives me the following error:
Exception when calling "OpenRead" with arguments "1": "The process can not get access to the file 'C: \ Users \ g \ Documents \ BAT \ GrabI.log' because it is being used in another process.
The powershell code used is the following:
@PowerShell ^
$N = 200; ^
$fpath = 'Grab%1.log'; ^
$fs = [System.IO.File]::OpenRead($fpath); ^
$fs.Seek(-$N, 'End') ^| Out-Null; ^
$mystr = ''; ^
for ($i = 0; $i -lt $N; $i++) ^
{ ^
$mystr = ($mystr) + ([char[]]($fs.ReadByte())); ^
} ^
Write-Host $mystr > logtmp%1.log
%End PowerShell%
Is there any way to do the Open that allows me to access the file in read mode even if it is in use?