PLearn 0.1
|
#include <AutoRunCommand.h>
Public Member Functions | |
AutoRunCommand () | |
virtual void | run (const vector< string > &args) |
The actual implementation of the 'AutoRunCommand' command. | |
Static Protected Attributes | |
static PLearnCommandRegistry | reg_ |
This allows to register the 'AutoRunCommand' command in the command registry. |
Definition at line 50 of file AutoRunCommand.h.
PLearn::AutoRunCommand::AutoRunCommand | ( | ) | [inline] |
Definition at line 53 of file AutoRunCommand.h.
: PLearnCommand("autorun", "watches files for changes and reruns the .plearn script", "watch <script.plearn> [other files to watch]\n" "Will run the .plearn script once and watches its and other files for changes.\n" "Will rerun the script automatically each time its date changes \n" "or the date of one of the watched files changes. \n" ) {}
void PLearn::AutoRunCommand::run | ( | const vector< string > & | args | ) | [virtual] |
The actual implementation of the 'AutoRunCommand' command.
Implements PLearn::PLearnCommand.
Definition at line 60 of file AutoRunCommand.cc.
References PLearn::endl(), PLearn::PLearnError::message(), PLearn::mtime(), PLearn::RunCommand::run(), and PLearn::times().
{ string scriptname = args[0]; int nargs = int(args.size()); vector<string> runargs(1); runargs[0] = scriptname; TVec<time_t> times(nargs); for(;;) { try { RunCommand rc; cerr << ">>> Running script " << scriptname << endl; rc.run(runargs); } catch(const PLearnError& e) { cerr << "FATAL ERROR running script " << scriptname << "\n" << e.message() << endl; } sleep(1); // Store times for(int k=0; k<nargs; k++) times[k] = mtime(args[k]); bool up_to_date = true; while(up_to_date) { sleep(1); for(int k=0; k<nargs; k++) if(times[k] < mtime(args[k])) { cerr << " File " << args[k] << " has changed." << endl; up_to_date = false; } } } }
PLearnCommandRegistry PLearn::AutoRunCommand::reg_ [static, protected] |
This allows to register the 'AutoRunCommand' command in the command registry.
Definition at line 68 of file AutoRunCommand.h.