[comp.lang.perl] IPC Servers

steve@gapos.bt.co.uk (Steve A Rooke) (02/08/90)

As a novice perl hacker (of a few days) I have been looking at the
interprocess communication and want to set up a server that will start
up a unix executable and attach it to the pipe for the duration of the
session and when finished the server will start `listening again'.
I see there is a command `select' that I can change stdout to the socket
file handle but I can not find the command to change stdin in the same 
way.  As I said before, I'm not only a novice to perl but also to this IPC
stuff and it looks as though perl will allow me to gain useful experience
in this area.

Now don't laugh (or ask me why I wan't to do it) but the first reason I
want to use the above for is to run `sendmail -bs' ie get sendmail to talk
SMTP on it's stdin/out.  Yes I know sendmail has IPC but I can't use it!

Thank's

Steve
---
Steve Rooke  steve@gapos.bt.co.uk  (...mcvax!ukc!gapos!steve)  UK + 394 693595
BT, ITS/CS, Area 106, Anzani House,   | "You roll the dice with your heart
Trinity Ave, FELIXSTOWE, Suffolk, UK  |   and soul,  But some times you
#include <std/disclaimer>             |    just don't know." - Sam Brown

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/10/90)

In article <1328@gapprd.gapos.bt.co.uk> steve@gapos.bt.co.uk (Steve A Rooke) writes:
: As a novice perl hacker (of a few days) I have been looking at the
: interprocess communication and want to set up a server that will start
: up a unix executable and attach it to the pipe for the duration of the
: session and when finished the server will start `listening again'.
: I see there is a command `select' that I can change stdout to the socket
: file handle but I can not find the command to change stdin in the same 
: way.

Select isn't doing what you think it's doing.

What you want is probably

	socket(SOCK, ...);
	bind(SOCK, ...);
	listen(SOCK, 5);
	accept(NSOCK, SOCK);

	$pid = fork;
	if (!$pid) {
	    open(STDIN, "<&NSOCK");
	    open(STDOUT,">&NSOCK");

	    close NSOCK;
	    close SOCK;
	    exec '/usr/lib/sendmail', '-bs';	# or whatever
	}
	$status = wait;
	...

Or some such.

Larry