Created
August 25, 2009 19:11
-
-
Save holizz/174941 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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