views:

3005

answers:

16

Hi, for debugging purpose in a somewhat closed system, I have to output text in a file.

Does anyone knows of a tool that runs on windows ( console based or not ) that detects changes to a file and outputs them in real-time ?

+16  A: 
Jon Galloway
haha i remember how we coined the phrase "tailing wget-log"(means waiting for a long download to finish)
Midhat
+2  A: 

I have used FileSystemWatcher for monitoring of text files for a component I recently built. There may be better options (I never found anything in my limited research) but that seemed to do the trick nicely :)

Crap, my bad, you're actually after a tool to do it all for you..

Well if you get unlucky and want to roll your own ;)

Rob Cooper
+5  A: 

I use "tail -f" under cygwin.

CHitchcock
+5  A: 

FileSystemWatcher works a treat, although you do have to be a little careful about duplicate events firing - 1st link from Google - but bearing that in mind can produce great results.

ZombieSheep
+2  A: 

Yor can use the FileSystemWatcher in System.Diagnostics.

From MSDN:

public class Watcher {

public static void Main()
{
Run();

}

[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
public static void Run()
{
    string[] args = System.Environment.GetCommandLineArgs();

    // If a directory is not specified, exit program.
    if(args.Length != 2)
    {
        // Display the proper way to call the program.
        Console.WriteLine("Usage: Watcher.exe (directory)");
        return;
    }

    // Create a new FileSystemWatcher and set its properties.
    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.Path = args[1];
    /* Watch for changes in LastAccess and LastWrite times, and 
       the renaming of files or directories. */
    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite 
       | NotifyFilters.FileName | NotifyFilters.DirectoryName;
    // Only watch text files.
    watcher.Filter = "*.txt";

    // Add event handlers.
    watcher.Changed += new FileSystemEventHandler(OnChanged);
    watcher.Created += new FileSystemEventHandler(OnChanged);
    watcher.Deleted += new FileSystemEventHandler(OnChanged);
    watcher.Renamed += new RenamedEventHandler(OnRenamed);

    // Begin watching.
    watcher.EnableRaisingEvents = true;

    // Wait for the user to quit the program.
    Console.WriteLine("Press \'q\' to quit the sample.");
    while(Console.Read()!='q');
}

// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
    // Specify what is done when a file is changed, created, or deleted.
   Console.WriteLine("File: " +  e.FullPath + " " + e.ChangeType);
}

private static void OnRenamed(object source, RenamedEventArgs e)
{
    // Specify what is done when a file is renamed.
    Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}

}

You can also follow this link Watching Folder Activity in VB.NET

nmiranda
A: 

FileMon is a free stand alone tool that can detect all kinds of file access. You can filter out any unwanted. It does not show you the data that has actually changed though.

Lars Truijens
A: 

I second "tail -f" in cygwin. I assume that Tail for Win32 will accomplish the same thing.

Owen
+4  A: 

When using Windows PowerShell you can do the following:

Get-Content someFile.txt -wait
Lars Truijens
+2  A: 

Tail is the best answer so far.

If you don't use Windows, you probably already have tail.

If you do use Windows, you can get a whole slew of Unix command line tools from here: http://unxutils.sourceforge.net/ - Unzip them and put them somewhere in your PATH.

Then just do this at the command prompt from the same folder your log file is in:

tail -n 50 -f whatever.log

This will show you the last 50 lines of the file and will update as the file updates.

You can combine grep with tail with great results - something like this:

tail -n 50 -f whatever.log | grep Error

gives you just lines with "Error" in it

Good luck!

+4  A: 

I use BareTail for doing this on Windows. It's free and has some nice features, such as tabs for tailing multiple files and configurable highlighting.

John Topley
+1  A: 

Just a shameless plug to tail onto the answer, but I have a free web based app called Hacksaw used for viewing log4net files. I've put in an auto refresh options so you can give yourself near real time updates without having to refresh the browser all the time.

Dillie-O
A: 

Yeah I've used both Tail for Win32 and tail on Cygwin. I've found both to be excellent, although I prefer Cygwin slightly as I'm able to tail files over the internet efficiently without crashes (Tail for Win32 has crashed on me in some instances).

So basically, I would use tail on Cygwin and redirect the output to a file on my local machine. I would then have this file open in Vim and reload (:e) it when required.

redspike
A: 

+1 for BareTail. I actually use BareTailPro, which provides real-time filtering on the tail with basic search strings or search strings using regex.

Rob Thomas
+2  A: 

I like tools that will perform more than one task, Notepad++ is a great notepad replacement and has a Document Monitor plugin (installs with standard msi) that works great. It also is portable so you can have it on a thumb drive for use anywhere.

For a command line option, PowerShell (which is really a new command line) has a great feature already mentioned.

Get-Content someFile.txt -wait

But you can also filter at the command line using a regular expression

Get-Content web.log -wait | where { $_ -match "ERROR" }
Mike Schall
Very nice! +1
Optimal Solutions
A: 

Tail for Win32

rathkopf
A: 

To make the list complete here's a link to the GNU WIN32 ports of many useful tools (amongst them is tail). GNUWin32 CoreUtils

mandrake