[comp.sys.amiga] lattice c question

bader+@andrew.cmu.edu (Miles Bader) (10/20/88)

I'm using the forkv() call to run a subprocess.  I want to redirect
the suprocess's output to a file by (leaving out error checking):

static struct FORKENV env = {0,0,0,0,0,0};
file=fopen("...","w+"):
env.std_out=fileno(file);
forkv(prog,argv,&env,&child);
wait(&child);

This works when I don't try to redirect stdout (using NULL instead of
&env), and I've tried using "(long)file" instead of fileno(file), but
both guru.

So, is a fileno(...) the right type for env.std_out?  If not, what is
(and how do I get one from file)?

Thanks abunch... -Miles

toebes@sas.UUCP (John Toebes) (10/24/88)

In article <kXLIOly00UkaI8m4ca@andrew.cmu.edu> bader+@andrew.cmu.edu (Miles Bader) writes:
>I'm using the forkv() call to run a subprocess.  I want to redirect
>the suprocess's output to a file by (leaving out error checking):
>
>static struct FORKENV env = {0,0,0,0,0,0};
>file=fopen("...","w+"):
>env.std_out=fileno(file);
>forkv(prog,argv,&env,&child);
>wait(&child);
>
>This works when I don't try to redirect stdout (using NULL instead of
>&env), and I've tried using "(long)file" instead of fileno(file), but
>both guru.
>
>So, is a fileno(...) the right type for env.std_out?  If not, what is
>(and how do I get one from file)?
>Thanks abunch... -Miles

You need to pass it an AmigaDos file handle (an inherited process could not
utilize the I/O subsytem from the parent process.  To get this you need:

   #include <dos.h>

   env.std_out=chkufb(fileno(file))->ufbfh;

To illustrate what this does:
    fileno(file)    translates a level2 file handle to a level1 file number
    chkufb(fn)      Obtains the low level UFB structure for the level1 file
    ufb->ufbfh      extracts the AmigaDos file handle from the UFB structure

Incidently, this magic works with 3.10, 4.0, 4.01, and 5.0 even though
there are major differences in some of the low level I/O implementations.
It will continue to work in the future (as we depend upon it internally).

/*---------------------All standard Disclaimers apply---------------------*/
/*----Working for but not officially representing SAS or Lattice Inc.-----*/
/*----John A. Toebes, VIII             usenet:...!mcnc!rti!sas!toebes-----*/
/*------------------------------------------------------------------------*/