Article 173654 of comp.os.vms:
In article <1997070908425669127@zetnet.co.uk>, Dave Stevenson <dave.stevenson@zetnet.co.uk> writes:
>Can someone help me with this query please ?
>
>I need to use LIB$SPAWN to execute either a command procedure 
>(probably) or another program (possibly). I cannot get my head around 
>how to pass the required arguments "by descriptor". I am running DEC 
>C on an Alpha (OpenVMS 6.2), unfortunately, I only have a VAX C 
>manual, which gives some brief description of descriptors. I also 
>have the RTL LIB$ manual, which doesn't provide too much help (well, 
>not to me anyway).
>
>Can someone please advise if there is a better explanation of the use 
>of descriptors (for dummies) elsewhere in the bookset, or a small 
>example please ?
>

This code *fragment* should be close to what you want (it is from my port of 
XLDLAS to OpenVMS, but most of the pieces you see here are pretty much
verbatim from an older PERL distribution).  It creates a mailbox, opens a 
FILE into it, then spawns a subprocess which reads from that mailbox.  The
FL_ stuff you can ignore, that is for Xforms calls.  In XLDLAS this is used
to stuff GNUPLOT commands into a subprocess, and so generate plots from 
statistics data.


/* you may need more or less of these, sorry! */
#include <libdef.h>
#include <lib$routines.h>
#include <ssdef.h>
#include <stsdef.h>
#include <descrip.h>


/* prototype for create_mbx */
extern int  create_mbx(unsigned short int *, struct dsc$descriptor_s *);

/* this is in the function that uses it */
    static char mbxname[64];
    unsigned short int chan;
    unsigned long int pid, flags=1;
    unsigned long int status;
    int fd ;
    int oflags = O_RDWR;
    struct dsc$descriptor_s namdsc = {sizeof mbxname, DSC$K_DTYPE_T,
                                      DSC$K_CLASS_S, mbxname},
                            cmddsc = {0, DSC$K_DTYPE_T,
                                      DSC$K_CLASS_S, 0};


    cmddsc.dsc$w_length=strlen(GNUPLOT_CMD);
    cmddsc.dsc$a_pointer=GNUPLOT_CMD;
    /* create mailbox, note, it comes up with the name */

    status = create_mbx(&chan, &namdsc);
    if(status != 1){
        fl_show_alert("I Can't Start GNUPlot (create_mbx() failed)","","",TRUE);
        return(-1);
    }

    /* open a FILE * into it */

    fd=open(mbxname, oflags, 0);

    if(fd == -1){
        sys$delmbx(chan);
        fl_show_alert("I Can't Start GNUPlot (fopen() failed)","","",TRUE);
        return(-1);
    }

    status = lib$spawn(&cmddsc, /* command string */
                       &namdsc, /* input file */
                       0,       /* sys$output */
                       &flags,  /* flags */
                       0,       /* process name */
                       &pid,    /* process ID */
                       0, /* completion status address */
                       0, 0, 0,0,0,0);

    if(status != 1){
        close(fd);
        sys$delmbx(chan);
        fl_show_alert("I Can't Start GNUPlot (lib$spawn() failed)","","",TRUE);
        return(-1);
    }


Regards,

David Mathog
mathog@seqaxp.bio.caltech.edu
Manager, sequence analysis facility, biology division, Caltech 
**************************************************************************
*Affordable VMS? See:  http://seqaxp.bio.caltech.edu:8000/www/pcvms.html *
**************************************************************************


