<small id='S78f5'></small><noframes id='S78f5'>

        <i id='S78f5'><tr id='S78f5'><dt id='S78f5'><q id='S78f5'><span id='S78f5'><b id='S78f5'><form id='S78f5'><ins id='S78f5'></ins><ul id='S78f5'></ul><sub id='S78f5'></sub></form><legend id='S78f5'></legend><bdo id='S78f5'><pre id='S78f5'><center id='S78f5'></center></pre></bdo></b><th id='S78f5'></th></span></q></dt></tr></i><div id='S78f5'><tfoot id='S78f5'></tfoot><dl id='S78f5'><fieldset id='S78f5'></fieldset></dl></div>
          <bdo id='S78f5'></bdo><ul id='S78f5'></ul>
        <legend id='S78f5'><style id='S78f5'><dir id='S78f5'><q id='S78f5'></q></dir></style></legend>
      1. <tfoot id='S78f5'></tfoot>
      2. 如何捕获 subprocess.call 的输出

        时间:2023-10-11

            • <legend id='XUauh'><style id='XUauh'><dir id='XUauh'><q id='XUauh'></q></dir></style></legend>
              <i id='XUauh'><tr id='XUauh'><dt id='XUauh'><q id='XUauh'><span id='XUauh'><b id='XUauh'><form id='XUauh'><ins id='XUauh'></ins><ul id='XUauh'></ul><sub id='XUauh'></sub></form><legend id='XUauh'></legend><bdo id='XUauh'><pre id='XUauh'><center id='XUauh'></center></pre></bdo></b><th id='XUauh'></th></span></q></dt></tr></i><div id='XUauh'><tfoot id='XUauh'></tfoot><dl id='XUauh'><fieldset id='XUauh'></fieldset></dl></div>
              <tfoot id='XUauh'></tfoot>

              <small id='XUauh'></small><noframes id='XUauh'>

                <tbody id='XUauh'></tbody>

                  <bdo id='XUauh'></bdo><ul id='XUauh'></ul>

                  本文介绍了如何捕获 subprocess.call 的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我制作了一个脚本,告诉我 Raspberry Pi 3 的温度,但脚本有问题.结果输出是机器人说您的 RPI3 温度当前为 0".我的代码有什么问题?

                  I have made a script that tells me the temperature of my Raspberry Pi 3, but there is a problem with the script. The result output is the bot saying "Your RPI3 temp is currently 0". What is wrong with my code?

                  @bot.command(pass_context=True)
                  async def vcgencmdmeasure_temp(ctx):
                      if ctx.message.author.id == "412372079242117123":
                          await bot.say("OK....")
                          return_code = subprocess.call("vcgencmd measure_temp", shell=True)
                          await bot.say("KK done")
                          await bot.say("Your RPI3 temp is currently: {}".format(return_code))
                      else:
                          await bot.say("Error user lacks perms(only bot owner can run this)")
                  

                  我知道想要运行任何命令.当前脚本

                  i know want to run any command. Current script

                  @bot.command(pass_context=True)async def rpicmd(ctx, *args):

                  @bot.command(pass_context=True) async def rpicmd(ctx, *args):

                  if ctx.message.author.id == "412372079242117123":
                      mesg = ''.join(args)
                      mesg = str(mesg)
                      command_output = subprocess.check_output(mesg, shell=True, universal_newlines=True)
                      await bot.say(command_output)
                  else:
                      await bot.say("No noob")
                  

                  我得到了错误:

                  raise CommandInvokeError(e) from e
                  discord.ext.commands.errors.CommandInvokeError: Command raised an 
                   exception: CalledProcessError: Command 'vcgencmdmeasure_temp' returned 
                    non-zero exit status 12
                  

                  推荐答案

                  return_code 会有进程的返回码.当一个进程成功存在(没有错误)时,它返回一个代码0.如果出错,则返回 1 代码(或非零值).如果你想要程序的输出(它打印到 stdout),这是获得它的一种方法:

                  return_code will have the return code of the process. When a process exists successfully (without error), it returns a code of 0. If it errors, it returns a code of 1 (or something non-zero). If you want the output of the program (that it prints to stdout), this is one way to get it:

                  p = subprocess.run("vcgencmd measure_temp", shell=True,stdout=subprocess.PIPE)
                  result = p.stdout.decode()
                  await bot.say("Your RPI3 temp is currently: {}".format(result))
                  

                  这篇关于如何捕获 subprocess.call 的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:你如何让 Discord 机器人删除用户对 discord.py 中消 下一篇:如何从 tweepy 异步 on_status?

                  相关文章

                  最新文章

                • <legend id='1jvEk'><style id='1jvEk'><dir id='1jvEk'><q id='1jvEk'></q></dir></style></legend><tfoot id='1jvEk'></tfoot>
                        <bdo id='1jvEk'></bdo><ul id='1jvEk'></ul>
                      <i id='1jvEk'><tr id='1jvEk'><dt id='1jvEk'><q id='1jvEk'><span id='1jvEk'><b id='1jvEk'><form id='1jvEk'><ins id='1jvEk'></ins><ul id='1jvEk'></ul><sub id='1jvEk'></sub></form><legend id='1jvEk'></legend><bdo id='1jvEk'><pre id='1jvEk'><center id='1jvEk'></center></pre></bdo></b><th id='1jvEk'></th></span></q></dt></tr></i><div id='1jvEk'><tfoot id='1jvEk'></tfoot><dl id='1jvEk'><fieldset id='1jvEk'></fieldset></dl></div>

                      <small id='1jvEk'></small><noframes id='1jvEk'>