Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!nat.vu.nl!maart From: maart@nat.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.shell Subject: Re: getting exit status from background job in sh Message-ID: <1991Jun05.205638.19112@nat.vu.nl> Date: 5 Jun 91 19:25:38 GMT Article-I.D.: nat.1991Jun05.205638.19112 References: <18999@cgl.ucsf.EDU> <1991Jun3.180151.11210@dartvax.dartmouth.edu> Organization: Dept. of Physics, Vrije University, Amsterdam, The Netherlands Lines: 33 In article , rodgers@clausius.mmwb.ucsf.edu writes: >[...] we have modified it a bit so that it >can, upon specification of an option, save the status in a file, which is >useful if the rsh command is placed in the background from within a script. >One can then carry on with other work, then use the wait command to ensure >that rsh is done, read the exit status from the file, and act appropriately. You need not modify `ersh' to accomplish what you want. This is how to do it in the Bourne shell: ersh machine cmd < input > output 2> errors & pid=$! # remember the process ID # lots of other commands wait $pid # wait for the specified process status=$? # the exit status of the process is returned If you _must_ use a file, use the following: (ersh machine cmd redirections; echo $? > status_file) & In the csh you would have to resort to this: ((ersh machine cmd < input > output) >& errors; \ echo $status > status_file) & >So on to a related problem: if one puts a LOCALLY executed command into the >background from within a script, then later issues a wait command so as to be >able to do something with output from the command, how can one cause the exit >status for the background command to have been saved in a file? That question has been answered by now.