Jump to content











Photo
- - - - -

ImDisk to read log file while another process writes

imdisk

  • Please log in to reply
6 replies to this topic

#1 Tango

Tango
  • Members
  • 3 posts
  •  
    United States

Posted 03 February 2014 - 08:35 PM

Hello, I have a few applications that write log files while running (that I don't have the ability to change) and unfortunately the developers are locking the log file while it is being written (not sure why they would do this other than not knowing about windows file api perhaps). What I would like to do is similar to the bash command tail -f on each of these log files while they are being written to. I was thinking I could create some kind of symlink to a ram disk and then read them from the ram disk. I created a junction on the parent directory of the log files to a ImDisk ramdisk and then try opening them there but I still get the same problem with an error of "that file is in use by another process". Can ImDisk help me here? Is there a way to read a symbolic link to a log file from ram disk ? I would prefer an approach I can use programatically. Other ideas about how I could tail a log file that is locked while being written to?

 

v/r

 

-Tim



#2 v77

v77

    Silver Member

  • Team Reboot
  • 566 posts
  •  
    France

Posted 03 February 2014 - 09:48 PM

I see two simple possibilities:

- if your drive/ramdisk is not too big: making an image of it and opening the image. Right-click on a drive letter, choose "Save disk contents as image file" (administrative privilege required). Next, right-click on the image file, "Mount as ImDisk Virtual Disk", and you're done.
For saving the image file, if this does not work, you can also enter the following command in an elevated command prompt:
rundll32.exe imdisk.cpl,RunDLL_SaveImageFile name_of_your_file

- using another tool that is able to read files in use, like Recuva, which have an option "Scan for non-deleted files". This often works because Recuva accesses the disk directly.



#3 Olof Lagerkvist

Olof Lagerkvist

    Gold Member

  • Developer
  • 1415 posts
  • Location:Borås, Sweden
  •  
    Sweden

Posted 04 February 2014 - 09:12 AM

Just to add to what v77 wrote, if you would like to do something like this from command line instead. The command line version of 7-zip can be used to read a filesystem without using filesystem driver. This means that if the log file is being written to R:\dir\logfile.txt, you could type:
7z x \\.\R: dir\logfile.txt

This will extract the possibly locked dir\logfile.txt from R: to dir\logfile.txt under the current directory.

It would not be exactly equivalent to tail -f, because you need to extract the logfile each time you wish to read it. There is no "follow" option with such methods. On the other hand, if you periodically run the above 7z command in one script and keep a tail --follow=name going in another window, you will get at least similar effect.


  • Tango likes this

#4 Tango

Tango
  • Members
  • 3 posts
  •  
    United States

Posted 06 February 2014 - 01:23 AM

7z x is to extract an archive ? the log file is not in an archive though. I tired the command but it just tells me my logfile.txt is not a valid archive. Do I need to archive the log then extract it



#5 Olof Lagerkvist

Olof Lagerkvist

    Gold Member

  • Developer
  • 1415 posts
  • Location:Borås, Sweden
  •  
    Sweden

Posted 06 February 2014 - 07:20 AM

No, 7z is in this case not used to extract from an archive. Instead, it is used to extract from the filesystem directly without going through the filesystem driver. I tested now again here and it works. Maybe you just missed the space between drive specification and path and thereby mistakenly specified the log textfile as an archive to 7z. That would not work, it is rather the drive itself that is an "archive" in this case and path to the logfile simply specifies which file to extract from that "archive".

#6 Tango

Tango
  • Members
  • 3 posts
  •  
    United States

Posted 07 February 2014 - 04:19 AM

Well I try to enter it as you say

c:\>C:\Users\tim\Downloads\7za920\7za.exe x \\.\C: temp\log.txt

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18


Error:
cannot find archive

c:\> 

I have used the 7z command line many times but I guess i don't get this. thanks for trying to help. Ill spend some time reading the docs



#7 Olof Lagerkvist

Olof Lagerkvist

    Gold Member

  • Developer
  • 1415 posts
  • Location:Borås, Sweden
  •  
    Sweden

Posted 07 February 2014 - 08:36 AM

You still practically need to redirect the log to a smaller drive first. If you had the log on an ImDisk drive R:, then the command line that uses the drive itself as an archive usually works.

I understand that this might be difficult to follow. There is another way to do the exact same thing, but might be easier to understand. First create an ImDisk drive L: connected to an image file c:\logfiles.img.
imdisk -a -s 200M -f C:\logfiles.img -m L: -p "/fs:fat /q /y"
Then, redirect the log file to L:. Now, if the log file is in L:\logs\logfile.txt, run:
7z x C:\logfiles.img log\logfile.txt
That should work too, but I have not tested the exact command line right now. I hope it still could be of some help!





Also tagged with one or more of these keywords: imdisk

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users