Path: utzoo!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!sdd.hp.com!spool.mu.edu!uunet!cme!libes From: libes@cme.nist.gov (Don Libes) Newsgroups: comp.unix.programmer Subject: Re: Detecting exec(2) failing after performing fork(2)? Message-ID: <12004@muffin.cme.nist.gov> Date: 8 Mar 91 14:55:25 GMT References: <1991Mar4.231540.17644@nat.vu.nl> <1991Mar7.222033.4711@nat.vu.nl> Organization: National Institute of Standards and Technology Lines: 44 In article <1991Mar7.222033.4711@nat.vu.nl> maart@nat.vu.nl (Maarten Litmaath) writes: > shj@login.dkuug.dk (Stig Jacobsen) writes: >>Yeah! It was something like this that I wanted, where I get no >>ugly messages splattering over the parents screen and where I get >>an error return from the spawn call and not via some signal. [...] >The interface might be changed to: > int spawn(argv, pidp) > char **argv > int *pidp; >..and spawn() would return the PID in `*pidp'. If you have 'expect' (as of 1/91), you can use the library that comes with it from C or C++. The following functions exist: int exp_spawnl(file, arg0 [, arg1, ..., argn] (char *)0); char *file; char *arg0, *arg1, ... *argn; int exp_spawnv(file,argv); char *file, *argv[ ]; extern int exp_pid; Both of these fork a new process so that stdin, stdout, and stderr can be written and read by the current process. A file descriptor is returned which corresponds to the process's stdin, stdout, and stderr. the new process. exp_pid is set to the pid of the new process. An additional interface exists, styled after popen: FILE * exp_popen(command); char *command; In all of these, exec errors are returned by reading output of the new process (as the original poster requested). The library has a number of other related I/O functions to control interactive processes from C. See the man page for more info. Don Libes libes@cme.nist.gov ...!uunet!cme-durer!libes