[Tutor] Socket question.

Martin Walsh mwalsh at groktech.org
Thu May 17 04:56:21 CEST 2007

Hey Dude :)

Dude, WHOA! wrote:
> kinda thing. The problem is that the client I wrote doesn't receive
> data and display it, and it also only executes single word commands.

> Server side:
> #!/usr/bin/env python


> 	try:
> 		echo = Popen(command, stdout=PIPE).stdout.read()

On a linux system (and perhaps Windows as well), the type of 'command'
seems to be important and changes the behavior of Popen -- whether it be
string or sequence. If you pass a 'command' as a string that includes
arguments (ex. 'ls -l'), the above will raise an exception. I'm not sure
if the same applies to Windows. You could try passing command as a list
or tuple (ex command.split(), ['ls', '-l'], or similar), or add
'shell=True' to the Popen call.

> Client:
> #!/usr/bin/env python


> 	send = raw_input('Send: ')
> 	sock.send(send)
> 	sock.recv(2048)

Try 'print sock.recv(2048)'.

> 	sock.close()


More information about the Tutor mailing list