Process_Item.pm |
my $slashdot_news = "$Pgm_Root/data/web/slashdot_news.txt";
$p_slashdot_news = new Process_Item("get_slashdot_news > $slashdot_news");
start $p_slashdot_news if time_now('6:30 AM');
display $slashdot_news if done_now $p_slashdot_news;
$p_report_weblog = new Process_Item;
$p_report_weblog ->set_output("$config_parms{data_dir}/weblog_results.txt");
if (time_now '2 AM') {
set $p_report_weblog "report_weblog /mh/data/logs/server.$Year_Month_Now.log";
start $p_report_weblog;
}
Example of multiple commands
$test_process1 = new Process_Item;
set $test_process1 'sleep 1', 'sleep 2';
add $test_process1 'sleep 1';
Example of running an internal mh subroutine $v_test_ftp = new Voice_Cmd 'Test background ftp [get,put]'; $p_test_ftp = new Process_Item; if ($state = said $v_test_ftp) { set $p_test_ftp "&main::net_ftp(file => '/tmp/junk1.txt', " . "file_remote => 'incoming/junk1.txt'," . "command => '$state')"; set_timeout $p_test_ftpb 60*2; start $p_test_ftpb; } print_log "Ftp command done" if done_now $p_test_ftp;
More examples are in mh/code/examples/test_process.pl
You can use this object to run external programs. On Win32 systems, the Win32::Process function is used. On Unix systems, the fork function is used. On either system, the following methods work in the same way:
new('program1 arguments', 'program2 arguments', ...)
set('program1 arguments', 'program2 arguments', ...)
set_timeout($timeout)
Process will timeout after $timeout seconds
set_output($output_file)
Program STDOUT errata goes to $output_file
set_errlog($errlog_file)
Program STDERR errata goes to $errlog_file
add('program3 arguments', 'program4 arguments', ...)
If you specify more than one program, they are run sequentially. done_now returns 1 after the last program is done. If program starts with &, then 'program arguments' is eval-ed as an internal mh function. Otherwise, 'program arguments' is run as an external command. On Windows, the &-> eval trick is supposed to work with perl 5.6+ (which has fork), but unfortunately, it causes perl to crash often, so is probably not useful yet.
start(OptionalArguements)
Starts the process with optional program arguements
done
Returns the time (seconds since epoch) that the process finished. If the process has been started, but has not yet finished, it returns 0.
pid
Returns the process id
timed_out
Returns the time when the process timed out. done_now will still trigger for a timed_out process.
done_now
Is true for the pass that the process finished on.
stop
Stops the process. If called as a stand alone function (not as an object method), all active Process_Items are stopped.
nice_level
Support for setting "nice" level; only useful for *nix
get_type()
Returns the class (or type, in Misterhouse terminology) of this item.
NONE
UNK
NONE
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Process_Item.pm |