I've pulled out the code that runs the external program... something like this:
EDIT: I should have noted that I am in the process of changing the way to run the external program, and that is why the code I first posted in this thread uses AssignStream, and the code below uses TProcess. The mis-behavior is the same.
program runtest;
uses SysUtils, StrUtils, Unix,
PgmData,
BaseUnix,
Classes, Process;
var
tf : text;
...
i,j : integer;
function RunBatch: integer;
const
TDiffToSecs = 100000.0;
var
istat : integer;
i : integer;
j : integer;
tf : text;
P : TProcess;
aline : string;
PID : cint;
checkt : cardinal;
currPri : cint;
newPri : cint;
Cindex : cardinal;
PStart : TDateTime;
runtime : cardinal;
begin
istat := 0;
// Create/CD into directory specific to user
// .....
System.Assign (tf, 'run.IN');
ReWrite (tf);
<write data to 'tf'>
Close (tf);
P := TProcess.Create(nil);
P.CommandLine := 'pgm run';
P.Execute;
PStart := now;
PID := P.ProcessID;
currPri := fpGetPriority(prio_process,PID);
Cindex := 0;
checkt := CheckTimes[Cindex];
while (P.Running) do
begin
sleep (checkt);
runtime := round ((now - PStart) * TDiffToSecs);
if (Cindex < MaxIntervals) then
begin
if (runtime >= TransTimes[Cindex]) then
begin
inc (Cindex);
checkt := CheckTimes[Cindex];
newpri := currPri + Cindex;
fpSetPriority (prio_process,PID,newpri);
end;
end
else if (runtime >= MaxRunTime) then
begin
fpKill (PID,SigKill);
istat := 999;
end;
end; // while running
P.Free;
if (istat = 0) then
begin
System.Assign (tf, 'run.OUT');
Reset (tf);
while (not eof(tf)) do
begin
Readln (tf,aline);
// writeln (Sout,aline);
writeln (aline);
end;
Close (tf);
end
else
begin
// writeln (Sout,'*ERROR Job ran too long');
end;
RunBatch := istat;
end;
begin
RunBatch;
end.
It runs fine as a standalone program, but hangs when waiting for input in the larger program. When I kill the tcp-connected client on the other computer it spits out the results.
Anyone have a clue as to why it hangs? This is a project killer.
Walter