stdout from spawn?

Dan Maas danieljmaas at yahoo.com
Tue May 6 07:38:23 EDT 2003


> 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.

Stdin/stdout redirection (>, |, etc) is done by the shell, not the
kernel. In other words, you need to run /bin/sh and tell it to execute
the command.

I think the -c switch is what you need (untested):

os.spawnvp(os.P_NOWAIT, '/bin/sh', ('/bin/sh', 'c', 'tar -tvf
/dev/tape > /tmp/tar.out'))

Or, you could manually hook up stdout to /tmp/tar.out using dup(), and
then fork() and exec() tar.

Dan




More information about the Python-list mailing list