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


In reply to Re: Launching a process by EvdB
in thread Launching a process by EyeOpener

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.