[fpc-pascal]redirecting prog under Linux

Andreas K. Foerster Andreas at AKFoerster.de
Sun Mar 31 19:42:05 CEST 2002


Hello,

I got the solution now!

On Sat, Mar 30, 2002 at 02:03:34PM +0100, Sebastian G√ľnther wrote:

> > How is it possible to run it on a different virtual terminal? 
> > Say /dev/tty2 for example.
> 
> I think you just have to open /dev/tty2 and pass the file handle as 
> StdOut and StdErr to the newly spawned process.

Yes, that it is. I just didn't know, how.

But I'm doing it the other way round: the parent just creates a child
process, and the child redirects it's in- and output then.

> (use AssignStream instead of Execl)

No, AssignStream creates pipes.
But the source code of this command showed me, how to redirect the
handles. So thanks for the hint.

Here is my solution: (no error-handling yet)

{ run program as child process on a given device: }
procedure rundev(Prog: pathstr; dev: pathstr);
var pid : longint;
    f : text;
begin
pid := fork;
if pid=0 then
   begin
   assign(f,dev);
   reset(f); dup2(f,input); close(f);
   rewrite(f); dup2(f,output); dup2(f,stderr); close(f);
   Execl(Prog);
   halt(127);
   end;
end;


-- 
Tschuess
	Andreas




More information about the fpc-pascal mailing list