tags:

views:

338

answers:

1

I'm trying to get Python socket working as an alternative to calling the command line socat.

This socat command works fine:

echo 'cmd' | sudo socat stdio <path-to-socket>

but when I run this python code, I get an error:

>>> import socket
>>> s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
>>> s.connect(<path-to-socket>)
>>> s.send('cmd')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.error: (32, 'Broken pipe')

Any ideas what the issue is? Thanks.

+1  A: 

There's one obvious difference between your echo | socat line and your Python code, and that's the newline that echo adds but you don't send in your Python code. I don't see how that could cause the broken pipe error. Your basic approach seems fine, and it works fine when I test locally. Are you sure the server process isn't doing something extra here? Are you sure it's still listening, and hasn't, for example, closed the other end of the socket for some reason?

Thomas Wouters
Thanks, it was the newline.
Heinrich Schmetterling