Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-03

redirecting prog under Linux

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andreas K. Foerster

Hello,

I start a program like this:

procedure run(Prog: string);
var pid    : longint;
    status : longint;
begin
pid := fork;
if pid=0 then
   begin
   Execl(Prog);
   runerror;
   end;
waitpid(pid, @status, 0);
end;

How is it possible to run it on a different virtual terminal? Say /dev/tty2 for example.
Can I automaticaly switch to this VT?

(The program is meant to run just in a special environment, so I know which terminals are free)

Tschuess Andreas

Reply by email

Sebastian Günther
to Andreas K. Foerster
Andreas K. Foerster wrote
Hello, I start a program like this:

[...]

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. (use AssignStream instead of Execl)

- Sebastian

Reply by email

Andreas K. Foerster
to Sebastian Günther

Hello,

I got the solution now!

Sebastian Günther wrote 5 lines
> 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

Reply by email