From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 15-MAY-1991 22:43:41.97
To:	ARISIA::EVERHART
CC:	
Subj:	Re: Wanted: "expect" for VAX/VMS

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.97)
	 id AA11853; Wed, 15 May 91 10:14:41 EDT
Received: From ucbvax.Berkeley.EDU ([128.32.133.1]) by CRVAX.SRI.COM with TCP; Wed, 15 MAY 91 06:18:04 PDT
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA11481; Wed, 15 May 91 06:17:39 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 15 May 91 12:56:07 GMT
From: dftsrv!oneel@mimsy.umd.edu  ( Bruce Oneel )
Organization: STX/GSFC Nasa
Subject: Re: Wanted: "expect" for VAX/VMS
Message-Id: <ONEEL.91May15085607@heawk1.gsfc.nasa.gov>
References: <1991May14.140929.153@gnv.ifas.ufl.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <1991May14.140929.153@gnv.ifas.ufl.edu> dis@gnv.ifas.ufl.edu writes:



      Could someone tell me where I can find the UNIX "expect" work-like software
      for VAX/VMS.
      Thanks in advance,

      Ciqin Ding
      dis@gnv.ifas.ufl.edu
      dis@ifasgnv

 It's a "you have to write it" but you can fairly easily do it using
 mailboxes and qios with time outs.  Go get your local copy of the i/o
 manuals and the system service manuals.  As a start, included below is
 a quicky version in C of unix's popen command, which is one half of
 the job (the easy half).  You have to create a mailbox and then do i/o
 to it using qios with timeouts to take care of the output of the
 subprocess.

 bruce

/* This is a version of popen/pclose for VAX/VMS.

	popen should be just like the Sun OS version, so quite unix like

	pclose does not currently wait for the subprocess to finish!  This
	is a bug but I haven't fixed it yet.


	This is very VAX/VMS specific, but thats the point...


*/

#include <descrip.h>
#include <stdio.h>



/* popen starts up command and returns a FILE * to it's input if type is "w"
	and to it's output if type is "r"

	returns NULL if unsucessful.

*/

FILE *popen (command,type)
char *command, *type;

{
	int chan;	/* Dummy channel for sys$crembx */
	int istat;
	int flag;
	$DESCRIPTOR (log_name,"TMP_MAILBOX");
	$DESCRIPTOR (terminal,"TT");
	struct dsc$descriptor_s prog_desc;

	prog_desc.dsc$w_length = strlen(command);
	prog_desc.dsc$b_dtype = DSC$K_DTYPE_T;
	prog_desc.dsc$b_class = DSC$K_CLASS_S;
	prog_desc.dsc$a_pointer = command;

	
	istat = sys$crembx(0,&chan,0,0,0,0,&log_name);
	if (istat != 1) 
	{
		fprintf (stderr,"popenf: create mailbox failed\n");
		return NULL;
	}


	flag = 1;
	if (0 == strcmp(type,"r")) 
	{
		istat = lib$spawn(&prog_desc,&terminal,&log_name,&flag);
	} else {
		istat = lib$spawn(&prog_desc,&log_name,&terminal,&flag);
	}

	if (istat != 1) 
	{
		fprintf (stderr,"popenf: spawn failed for %s\n",command);
		return NULL;
	}

	return (fopen(log_name.dsc$a_pointer,type));
}


pclose(stream)
FILE *stream;
{
	fclose (stream);
}
--
Bruce O'Neel              oneel@heasfs.gsfc.nasa.gov
NASA/GSFC/STX/Code 664

