#!/usr/bin/python import sys import os import logging import popen2 if len(sys.argv) != 2: logging.error('Usage: %s " "' % sys.argv[0]) sys.exit(1) args = sys.argv[1].split(' ') jid = args[0] text = ' '.join(args[1:]) logging.info("Saying '%s' to %s" % (text, jid)) if not os.fork(): # Returns 0 in child process sendxmpp = popen2.Popen3(cmd=['/usr/bin/sendxmpp', '-t', jid], capturestderr=True) sendxmpp.fromchild.close() sendxmpp.tochild.write(text) sendxmpp.tochild.close() result = sendxmpp.wait() if os.WIFEXITED(result): logging.info('Exit code: %i' % os.WEXITSTATUS(result)) else: logging.warn('sendxmpp did not exit()')