static char szModuleName__ []  = "f:/r3/code/c/unix/execute.c";
static char szLastVersion []   = "Version 0.1";
static char szLastSave []      = "1995-08-25*10:44";
/* --------------------------- encbuf.c --------------------------------- */
/* Rev:
        94-09-27 ARG switched use of datim and trtim
   --------------------------- encbuf.c --------------------------------- */

#ifdef VMS
#include descrip
#include <types.h>
#include <stdio.h>
#include <string.h>
#else
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#endif

#include "apitypes.h"
#include "netdef.h"
/* ------------------------------------------------------------------------ */
#ifdef VMS
/*  BUILD DESCRIPTORS   */
  static $DESCRIPTOR(cmdstr,"");
  static $DESCRIPTOR(infil,"");
  static $DESCRIPTOR(outfil,"");
  static $DESCRIPTOR(procname,""); 
#endif
/*
main(argc,argv) 
int argc; 
char *argv[];
*/

#ifdef VMS
/*========================= V M S - P A R T Of code =========*/
void spawnCallback(void) /*
==================================*/
{
  /*
    printf(" Spawned process terminated \n");
    */
}

INT32 NradExecute(char *argv[] ) /*
=================================================*/
{ int iIx=1;               /* StrCpy first to garantie clean buf at start.*/
  static	int retcode, sizet;
  static	long status = 0;
  static	long flags = 0;
  static	unsigned char event_flag; 
  static  char NullDev[] ="NL:";
  char  VMS_Command[150];

  strcpy( VMS_Command,  argv[0] );
  
  while (argv[iIx] != NULL) {
    strcat(VMS_Command," ");                     /* Insert separator*/
    strcat(VMS_Command,argv[iIx++]);
    }
  
  cmdstr.dsc$b_class = DSC$K_CLASS_S; 
  cmdstr.dsc$b_dtype = DSC$K_DTYPE_T; 
  cmdstr.dsc$w_length = strlen(VMS_Command);
  cmdstr.dsc$a_pointer = VMS_Command; 

  outfil.dsc$b_class = DSC$K_CLASS_S;
  outfil.dsc$b_dtype = DSC$K_DTYPE_T;

  outfil.dsc$a_pointer = NullDev;
  outfil.dsc$w_length = strlen( NullDev);
  
  procname.dsc$w_length = 0;
  procname.dsc$a_pointer = 0;
  
  infil = procname;
  outfil = procname;

  retcode = lib$spawn(&cmdstr,&infil,&outfil,
	 	       &flags,&procname,&retcode,
		       &status,&event_flag,&spawnCallback);

  /*
  if (retcode != 1)
    printf("Lib$spawn wait retcode = %d \n",retcode);
   */

  if (status != 1) 
    return NOK;
  else 
    return OK;
}
#else
/*=============== U N I X - P A R T  of code ==================== */
int NradExecute(char *argv[] ) /*
==============================================*/
{ unsigned int iStatus;
  switch ( fork() ) {
  case -1:                                      /*Parent, could not spawn!*/
    printf("Can't create new process\n");
    return 1;
  case 0:                                       /*Child, will execute*/
    exit( execvp( argv[0], argv));
    return;
  default:                                      /*Parent,will wait*/
    if ( wait(&iStatus)== -1)
      printf("BufrPack:Err on SysCall wait\n");
    if ( iStatus>>8 )
      return NOK;
    else
      return OK;
  }
}
#endif

/* ------------------------ end of Execute.c ------------------------------ */
