Python: unix socket & # 8594; broken pipe
I am trying to get Python socket to work as an alternative to the socat command line call.
This socat command works great:
echo 'cmd' | sudo socat stdio <path-to-socket>
but when i run this python code i get the 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 idea what the problem is? Thanks.
+2
a source to share
2 answers
There is one obvious difference between your line echo | socat
and your Python code and that is a new line being added echo
, but you are not submitting Python code. I don't see how this can lead to a pipe break error. Your basic approach seems fine, and it works great when I test locally. Are you sure the server process is not doing here? Are you sure it is still listening and for some reason hasn't closed the other end of the socket?
+4
a source to share