[comp.sys.amiga.tech] Invoking a sub-process

mcr@julie.UUCP (Michael Richardson) (04/29/89)

  I've been trying to rewrite my uuxqt program to deal with a soft-coded
commands, (as in L.cmds), return codes, and nifty stuff like that.
I want to redirect the standard input and invoke a new process (with
fexecv, Manx 3.6a) I've managed to pare the code that causes the GURU
I've been getting to the bare minimum. Here it is: (I know the
_devtab stuff doesn't need to be there.)

=======
#include <stdio.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <fcntl.h>

extern struct Task *FindTask();

main(argc,argv)
int argc;
char *argv[];
{
  int status,error;
  static char *av[30];
  int i;
  long oldin,newin;
  struct Process *myProc;

  if(argc<=2) {
    printf("Not enough args\n");
    exit(2);
  }
  myProc=(struct Process *)FindTask(0L);
  oldin=Input();

  if((newin=(long)Open(argv[1],MODE_OLDFILE))==NULL) {
    printf("Can't open %s\n",argv[1]);
    exit(1);
  }
  myProc->pr_CIS=newin;
  _devtab[stdin->_unit].fd=newin;

  argc=argc-2;
  for(i=0; i<argc; i++) {
    av[i]=argv[i+2];
    printf("Arg %d is %s\n",i,av[i]);
  }
  av[i]=NULL;

  status=fexecv(av[0],av);
  error=wait();

  _devtab[stdin->_unit].fd=myProc->pr_CIS=oldin;
  Close(newin);
  exit(status || error);

}
========================

  Compile with:
    cc +L test2.c
    ln +Q -w test2.o -o test2

  Run:
    test2 test2.c type          ;; no problem
    test2 test2.c type hex      ;; pretty neat
    test2 test2.c type opt h    ;; GURUs. No task held. Takes out $c00000 RAD:
    test2 test2.c echo hi there ;; ditto. And this doesn't even access stdin!

  I've managed to isolate this down to the fexecv call. I AM setting up
the arguments right, but it still dies. I haven't tracked all the way
through the fexecv code, and I'm not sure I ever will. From the Dillon
shell code I've looked at this ought to be the right thing to do...

  Any ideas? Anyone? Please? This keeps me up at night...










--

  :!mcr!:
  Michael Richardson                     Amiga
                                  v--------+
 UUCP: uunet!attcan!lsuc!nrcaer!julie!mcr  | INTERNET mcr@doe.carleton.ca
 Fido: Michael Richardson @ 1:163/109.10<--+ Alter @ 7:483/109.10