1
0
Fork 0

Initial release

This commit is contained in:
Daniele Tricoli 2009-06-20 11:22:12 +00:00
parent 73e6d81908
commit b554be3189
1 changed files with 68 additions and 0 deletions

68
weechat/exec.py Normal file
View File

@ -0,0 +1,68 @@
##
# (c) Copyright 2009 Daniele Tricoli aka Eriol <eriol@mornie.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
import subprocess
import weechat
DESC = '''Execute command(s) and print the output (only if called with -o).
e.g:
/exec ls
/exec -o toilet --irc Ciao!
'''
def exec_(server, args):
send_output = False
if not args:
weechat.prnt('You must provide a command to execute!')
return weechat.PLUGIN_RC_OK
elif args[:2] == '-o':
send_output = True
args = args[2:]
proc = subprocess.Popen(args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True,
shell=True)
stdout_value, stderr_value = proc.communicate()
if stderr_value:
error = ' '.join(stderr_value.split()[1:])
weechat.prnt('\x035' + error + '\x0F')
return weechat.PLUGIN_RC_OK
if send_output:
weechat.command(stdout_value)
else:
weechat.prnt(stdout_value)
return weechat.PLUGIN_RC_OK
weechat.register('exec',
'0.1',
'',
DESC)
weechat.add_command_handler ('exec',
'exec_',
'Execute command(s)',
'[-o] <command line>',
' -o : print output on current'
'server/channel\n')