Skip to content

Instantly share code, notes, and snippets.

@holizz
Created August 25, 2009 19:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holizz/174941 to your computer and use it in GitHub Desktop.
Save holizz/174941 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import socket
def uzblctrl(socket_file, input):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(socket_file)
sock.settimeout(0.5) # 500ms
sock.send(input+'\n')
output = ''
try:
while True:
buflen = 1024*1024 # 1M
buf = sock.recv(buflen)
output += buf
# Don't wait to timeout if we get short output
if len(buf) != buflen: break
except socket.timeout:
pass
sock.close()
if output[-1]: output = output[:-1]
return output
if __name__ == '__main__':
import sys
if len(sys.argv) == 3:
print uzblctrl(sys.argv[1], sys.argv[2])
else:
print 'usage: uzblctrl.py <socket_file> <input>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment