Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!gatech!mcnc!rti!sas!toebes From: toebes@sas.UUCP (John Toebes) Newsgroups: comp.sys.amiga Subject: Re: lattice c question Summary: Use chkufb Message-ID: <661@sas.UUCP> Date: 23 Oct 88 18:03:33 GMT References: Reply-To: toebes@sas.UUCP (John Toebes) Organization: SAS Institute Inc, Cary NC Lines: 38 In article 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 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-----*/ /*------------------------------------------------------------------------*/