使用 Willie 机器人输出不起作用,但打印可以

Outputting with Willie bot doesn't work, but print does

我正在尝试 return 使用 Willie 机器人将命令输出到 IRC 频道。

我的代码似乎可以逐行输出我的变量,但出于某种原因,一旦我使用 Willie 机器人 say 命令输出到 IRC,它就不会输出任何东西。

这是我的代码:

from willie import module
import subprocess
import urllib2
import os


@module.commands('splint')
def splint(bot, trigger):
    bot.reply('I will process your request now!')
    page = urllib2.urlopen(trigger.group(2))
    page_content = page.read();

    with open('codeToCheck.c', 'w') as code:
        code.write(page_content)

    command = 'splint "C:\Users\Justin\Desktop\codeToCheck.c"'
    output = subprocess.Popen(command,shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()[0]

    bot.say('I have saved the file successfully. Outputting:')

    for i in output.splitlines():
        bot.say(i)

    bot.say(output)

在这里使用我的小测试代码,我确定它适用于打印:

import subprocess,os

output = subprocess.Popen(["splint", "C:\cygwin64\home\Justin\codeToCheck.c"], stdout=subprocess.PIPE).communicate()[0]

command = 'splint "C:\Users\Justin\Desktop\codeToCheck.c"'
output = subprocess.Popen(command,shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()[0]

for i in output.splitlines():
    print i

print 'I have saved the file successfully. Outputting:'

这是我的代码的 irc 输出:

<Fogest> .splint http://pastebin.com/raw.php?i=8cB7DdnQ
<Fogbot> Fogest: I will process your request now!
<Fogbot> I have saved the file successfully. Outputting:

应该有输出,但是什么也没有。我在这里做错了什么吗? 运行 我的测试文件(我在 post 上显示的测试代码)通过命令行我得到了以下输出:

$ python test.py
Splint 3.1.2 --- 25 Aug 2010

Finished checking --- no warnings
I have saved the file successfully. Outputting:

我将代码改为使用以下代码:

process = subprocess.Popen(command,shell=True, stderr=subprocess.PIPE)
output = process.stderr.read()

问题现已解决。