From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 25-AUG-1993 14:00:45.89
To:	EVERHART
CC:	
Subj:	RE: Still having problems with SYS$CREPRC

Date: Wed, 25 Aug 1993 12:08:51 EDT
From: Mighty Firebreather <dragon@nscvax.princeton.edu>
To: elee52@castle.ed.ac.uk
CC: info-vax@sri.com
Message-ID: <009718C9.0FB19B20.4091@nscvax.princeton.edu>
Subject: RE: Still having problems with SYS$CREPRC

	elee52@castle.ed.ac.uk (Bill Gammie) writes:

>Hi,
>   I'm still having problems getting sys$creprc to
>work properly.  I want to create a subprocess (and
>sometimes a detached one) to do one of two things:
>
>1) run an executable (.exe file)
>2) run a command procedure (.com file) which
>   runs an executable with command line arguments -
>   the executable is compiled from DEC c code.
>
>Below is my test program.  It returns a value
>of 1 for sys$creprc but doesn't run my executables.
>
>If anyone could comment on/correct my code I'd be
>very grateful.
>
>Thanks again,
>
>Bill Gammie
>
>
>Bill Gammie                                Phone:031 650 5612
>Department of Electrical Engineering       email:bill@ee.ed.ac.uk
>University of Edinburgh
>
>PS.  I'm basically a unix person who's been working with
>VMS for the last seven weeks so I don't know too much
>about VMS.
>
>********************** begin included code **************************
>
>/*                                            */
>/* Test program to create a subprocess  */
>/* using SYS$CREPRC (VMS system service).     */
>/*                                            */
>/* 		Bill Gammie  		      */
>/*		18/8/1993		      */
>/*					      */
>
>/*     Include files             */
>
>#include <stdio.h>
>#include <stdlib.h>
>#include <string.h>
>#include <starlet.h>
>#include <ssdef.h>
>#include <prcdef.h>
>#include <prvdef.h>
>#include <descrip.h>
>#include <syidef.h>
>
>
>int main();
>
>int main()
>
>{
>
>	/* declare struct type for SYS$_CREPRC */
>
>	typedef struct
>	{
>		unsigned short length;
>		unsigned char  type;
>		unsigned char  class;
>		char	       *address;
>	} createstruct;
>
>	short status;
>	long pid;
>	long sub_pri = 4; /* priority for subprocesses */
>
>	char *image_name = "test1.exe";
>	char *input_name = "test1.com";
>	char *output_name = "test1.rpt";
>	char *process_name = "test1";
>
>	createstruct image_desc;
>	createstruct input_desc;
>	createstruct output_desc;
>	createstruct proc_name;
>
>	image_desc.length = strlen( image_name);
>	image_desc.address = image_name;
>	image_desc.class = DSC$K_CLASS_S;
>	image_desc.type= DSC$K_DTYPE_T;
>
>	input_desc.length = strlen( input_name);
>	input_desc.address = input_name;
>	input_desc.class = DSC$K_CLASS_S;
>	input_desc.type = DSC$K_DTYPE_T;
>
>	output_desc.length = strlen( output_name);
>	output_desc.address = output_name;
>	output_desc.class = DSC$K_CLASS_S;
>	output_desc.type = DSC$K_DTYPE_T;
>
>	proc_name.length = strlen( process_name);
>	proc_name.address = process_name;
>	proc_name.class = DSC$K_CLASS_S;
>	proc_name.type = DSC$K_DTYPE_T;
>
>
>
>
>	status=sys$creprc(&pid,&image_name,&input_name,
>			  &output_name,&output_name,0,0,
>			  &proc_name,sub_pri,0,0,0);
>
>
>	printf( "status = %d\n",status);
>
>	if (status != SS$_NORMAL)
>	{
>	   printf ( "CREPRC has returned abnormally - status = %d\n",status);
>	   exit(status);
>	}
>
>
>        return 0;  /* end of program  */
>}
>

	Here is a corrected program.  You will note that it is *much* 
shorter due to the use of the $DESCRIPTOR macro to define your string 
descriptors!  I also left out a bunch of includes that were not being used.
The program that you are trying to write may require them, the example did 
not.

	At least part of the problem with the original was that you were
passing pointers to pointers to strings rather than pointers to string 
descriptors; e.g. &image_name is the *address of* image_name which is 
declared as a pointer to a string.  It's a wonder that you didn't get a
failure code from SYS$CREPRC. 

/*                                            */
/* Test program to create a subprocess  */
/* using SYS$CREPRC (VMS system service).     */
/*                                            */
/* 		Bill Gammie  		      */
/*		18/8/1993		      */
/*					      */

/*     Include files             */

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

int main();

int main()

{
	short status;
	long pid;
	long sub_pri = 4; /* priority for subprocesses */

	$DESCRIPTOR(image_name, "test1.exe");
	$DESCRIPTOR(input_name, "test1.com");
	$DESCRIPTOR(output_name, "test1.rpt");
	$DESCRIPTOR(proc_name, "test1");


	status=sys$creprc(&pid,&image_name,&input_name,
			  &output_name,&output_name,0,0,
 			  &proc_name,sub_pri,0,0,0);


	printf( "status = %d\n",status);

	if (status != SS$_NORMAL)
	{
	   printf ( "CREPRC has returned abnormally - status = %d\n",status);
	   exit(status);
	}


        return 0;  /* end of program  */
}

	If you are going to create a *detached* process, and expect it to 
execute a command file, you must specify SYS$SYSTEM:LOGINOUT.EXE as the 
image to be executed in order to map the command interpreter into the
address space of your new process. 

*************************************************************************
*                        Here, there be dragons!                        *
*                      dragon@nscvax.princeton.edu                      *
*                                                                       *
*	I'm job hunting.  Any offers or leads will be appreciated.      *
* Thanks!                                                               *
*                                                Richard B. Gilbert     *
*************************************************************************

