首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与威利机器人输出不起作用,但打印

与威利机器人输出不起作用,但打印
EN

Stack Overflow用户
提问于 2015-02-01 00:34:23
回答 1查看 94关注 0票数 0

我试图使用Willie将命令的输出返回给IRC通道。

我的代码似乎可以逐行输出变量,但由于某种原因,一旦我使用威利机器人say命令输出给IRC,它就不会输出任何内容。

这是我的代码:

代码语言:javascript
复制
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)

在这里使用我的小测试代码,我已经确定它适用于print:

代码语言:javascript
复制
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输出在我的代码中的样子:

代码语言:javascript
复制
<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:

应该有产出,但什么也没有。我在这里做错什么了吗?通过命令行运行我的测试文件(我在这个帖子中显示的测试代码),我得到了如下输出,就像我应该得到的那样:

代码语言:javascript
复制
$ python test.py
Splint 3.1.2 --- 25 Aug 2010

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

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-01 01:14:31

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

代码语言:javascript
复制
process = subprocess.Popen(command,shell=True, stderr=subprocess.PIPE)
output = process.stderr.read()

这个问题现在解决了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28258169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档