Re: sockets, fork() & makefile()

Steven D. Majewski (sdm7g@Virginia.EDU)
Mon, 21 Dec 1992 14:46:43 +22306404 (EST)

I wrote:
sdm7g>The assignment to stdin and exec is the bit that I am suspicious of - will
sdm7g>python actually export that assignment ?

On Mon, 21 Dec 1992 Guido.van.Rossum@cwi.nl wrote:

>
> No, I'm sorry, it doesn't. I suggest you use popen() and construct a
> piece of shell syntax to redirect the socket's file number to 0,
> something like
>
> sock = socket(...) # Create a socket
> cmd = 'some_program arg1 arg2 ...' # A command and its arguments
> fd = sock.fileno() # Get the socket's file number as an integer
> cmd = cmd + ' 0<&' + `fd` # Append "0&<N" where N is the file number
> pipe = os.popen(cmd, 'w') # Fork+exec the program; it ignores its stdin
> pipe.close() # Write an EOF on the pipe
>

Thanks.
socket.fileno() is not in my copy of the library reference, but I *do* see
it there with "mysocket.__methods__" .
Your example, above, should be sufficient - I just want a python script that
will read in an initial command from a socket and dispatch to another
program, with input and output reassigned to the socket.

===============================================================================
Steven D. Majewski University of Virginia
sdm7g@Virginia.EDU Box 449 Health Sciences Center
Voice: (804)-982-0831 1300 Jefferson Park Avenue
FAX: (804)-982-1616 Charlottesville, VA 22908
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Former UVA Department of Physiology, now Department of Molecular Physiology
and Biological Physics! [ Still the same spacious offices in Jordan Hall
- only the letterhead has changed! ]