stdout from spawn?

Donn Cave donn at u.washington.edu
Mon May 5 13:45:23 EDT 2003


Quoth "Cipo Fuzo" <lists at panka.com>:
| I'm trying to run
|
| tar -tvf /dev/tape > /tmp/tar.out
|
| using os.spawn with the P_NOWAIT option.
| Howerver when I do
|
| pid =
| os.spawnvp(os.P_NOWAIT,'tar',('tar','-tvf','/dev/tape','>','/tmp/tar.out'))
|
| tar errors out because it gets '>' and '/dev/tape' as an argument.
|
| I need to start this in the background, and also need the process id.

Last I looked, this feature is missing from spawnv.  The procedure
you want, to get this effect, will look like spawnv (which you can
read yourself), but

   ...
   fd = os.open(outputfile, O_WRONLY)
   ... after fork, in child process (pid == 0)
       try:
         ...
         os.dup2(fd, 1)
         os.close(fd)
         ... go on to execve()

   ... in parent
   os.close(fd)

I open the file in the parent (and close it) because exceptions
will make more sense there.  The "try" statement is presumably
already there in the spawn function, to prevent exceptions from
throwing the child process into the parent program.

	Donn Cave, donn at u.washington.edu




More information about the Python-list mailing list