[comp.sys.amiga.tech] Lattice 4.0 forkl

brent@questar.QUESTAR.MN.ORG (Brent Nordquist) (07/27/88)

[ Elf: "crunch crunch crunch... mmmmm... thank you!" ]
[ Thanks to the author of DiskSounds for a good laugh at 3 A.M... ]

I am trying to get the Lattice 4.0 forkl() function to work "as
advertised" in the manual, to no avail.

I need to be able to start up another program with its stdin redirected
from somewhere else.  For example, the first process opens a file, sets
the stdin of the second process to be that file descriptor, and then
forks; then the second process, when reading from stdin, would be
reading from the file.

(BTW, I *don't* want to use Execute() or system() or ____(), because
I don't want to have to run off to SYS: to get the 'Run' command each
time.  [Tacky!]  I also need them to run concurrently.)

When I call forkl() with (struct ForkEnv *)NULL it works fine, with
the new process inheriting stdin from the current process.  Now, the
manual says I should also be able to pass a (struct ForkEnv *) whose
*fields* are NULL, and any NULL field will receive a default value.
So, I tried it, and I get the Guru.

First of all, the printed structure definition is wrong; the fields are
'std_in' and 'std_out,' not 'stdin' and 'stdout.'  (Wish I had the
manual with me so I could quote the page number.)  Also, the .h file
says they're BPTR's and not long's.  Are these 'file handles' returned
by open(), or is this something Amiga-specific?  (Can you say, "naive-
Amiga-programmer-used-to-mainframe-C?"  :-)

Perhaps forkl() isn't the best way to start up another process; can
someone give me some help?  Short example code would be invaluable!

Thanks!
-- 
Brent Nordquist                          Bachelorhood remaining:
brent@questar.mn.org                     
amdahl!bungia!questar!brent              20 weeks, 3 days, 19:00

riley@batcomputer.tn.cornell.edu (Daniel S. Riley) (07/28/88)

In article <1222@questar.QUESTAR.MN.ORG> brent@questar.QUESTAR.MN.ORG (Brent Nordquist) writes:
>I am trying to get the Lattice 4.0 forkl() function to work "as
>advertised" in the manual, to no avail.
>
>I need to be able to start up another program with its stdin redirected
>from somewhere else.  For example, the first process opens a file, sets
>the stdin of the second process to be that file descriptor, and then
>forks; then the second process, when reading from stdin, would be
>reading from the file.
>
>When I call forkl() with (struct ForkEnv *)NULL it works fine, with
>the new process inheriting stdin from the current process.  Now, the
>manual says I should also be able to pass a (struct ForkEnv *) whose
>*fields* are NULL, and any NULL field will receive a default value.
>So, I tried it, and I get the Guru.

I'd recommend filling in all the fileds if you're passing a ForkEnv at
all.  I get much more reliable results that way.

>Also, the .h file
>says they're BPTR's and not long's.  Are these 'file handles' returned
>by open(), or is this something Amiga-specific?  (Can you say, "naive-
>Amiga-programmer-used-to-mainframe-C?"  :-)

The manual also says that they are "file handles", which means that
these are AmigaDOS file handles as returned by the AmigaDOS Open()
(note capitalization) command, or Input() and Output().  You can also
use the Lattice _dopen() call, but note that (1) I believe it's _dopen,
not dopen, and (2) it returns a BPTR, not an int (the .h file says
long, which is better, but it should be BPTR).

>Perhaps forkl() isn't the best way to start up another process; can
>someone give me some help?  Short example code would be invaluable!

If you have arp, and can assume that anyone running will have arp,
you might look into AsyncRun, which I find to be a little more robust.
Otherwise, forkl() is probably the way to go (unless you want to run
BCPL commands in c:, in which case both AsyncRun and forkl will fail
miserably).

-Dan Riley (dsr@lns61.tn.cornell.edu, dsr@crnlns.bitnet)
-Wilson Lab, Cornell U.