in reply to Launching a process

Hello, I use the following bit of code to watch a file and to run a commandline option when it changes.
#!/usr/local/bin/perl -w # Usage: file-watch.pl file_to_watch interval commands_to_run # $Id: file-watch.pl,v 1.1.1.1 2003/06/12 12:20:13 evdb Exp $ use strict; my $file = shift @ARGV; my $SLEEP = shift @ARGV; my @CMD = @ARGV; die "Could not find the file $file.\n" unless -e $file; my $last_mod = (stat($file))[9]; my $self_mod = (stat($0))[9]; while (1) { my $curr_mod = (stat($file))[9]; if ( $curr_mod > $last_mod ) { $last_mod = $curr_mod; system @CMD; } else { sleep $SLEEP; } }

Create a file test.txt and then try file-watch.pl test.txt 3 'echo It Changed!'. When you touch the test file you will see the message. Greate for watching latex files that you are editing, compiling them, turning the dvi into ps and then sending HUP to gv to refresh the display.

file-watch.pl file.tex 2 "latex file.tex && latex file.tex && dvips -o file.ps file.dvi && killall -HUP gv"

You will of course have to add something else to the command line. You could also use cron if the scripts should run at a certain time.

--tidiness is the memory loss of environmental mnemonics