-
Notifications
You must be signed in to change notification settings - Fork 1
/
fpcron.pas
50 lines (48 loc) · 1.46 KB
/
fpcron.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{$mode objfpc}{$H+}
uses
Classes,SysUtils,DateUtils,Process;
var
CheckIntervalMilliSeconds,IntervalSeconds: Int64;
InputFilePath,TaskCommand: String;
TaskList: TStringList;
i: Integer;
LastExecTime: TDateTime;
begin
if ParamCount = 2 then begin
try
CheckIntervalMilliSeconds := StrToInt64(ParamStr(1));
InputFilePath := ParamStr(2);
TaskList := TStringList.Create;
while true do begin
Sleep(CheckIntervalMilliSeconds);
try
TaskList.LoadFromFile(InputFilePath);
for i := 0 to TaskList.Count - 1 do begin
ReadStr(TaskList[i],LastExecTime,IntervalSeconds,TaskCommand);
TaskCommand := Trim(TaskCommand);
if IncSecond(LastExecTime,IntervalSeconds) <= Now then begin
with TProcess.Create(nil) do begin
Options := [];
CommandLine := TaskCommand;
Execute;
Free;
end;
TaskList[i] := Format('%.16f %d %s',[Now,IntervalSeconds,TaskCommand]);
end;
end;
TaskList.SaveToFile(InputFilePath);
except
on e: Exception do begin
WriteLn(StdErr,e.Message);
end;
end;
end;
except
on e: Exception do begin
WriteLn(StdErr,e.Message);
end;
end;
end else begin
WriteLn('Usage: ' + ExtractFileName(ParamStr(0)) + ' <check interval in milliseconds> <input file path>')
end;
end.