Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Robot框架:如何将控制台输出重定向到文件_Python_Robotframework - Fatal编程技术网

Python Robot框架:如何将控制台输出重定向到文件

Python Robot框架:如何将控制台输出重定向到文件,python,robotframework,Python,Robotframework,我想知道是否有可能将Robot框架的stdout从控制台重定向到文件?当前,当我运行pybot时,输出在命令提示符下(对于Windows),我可以将其更改为转到文件吗?(命令提示符上没有显示任何内容)。除了@Bryan的建议外,如果您想将输出(xml、日志、报告)重定向到特定目录或文件,您可以对pybot脚本使用以下选项: -d --outputdir dir Where to create output files. The default is the

我想知道是否有可能将Robot框架的stdout从控制台重定向到文件?当前,当我运行pybot时,输出在命令提示符下(对于Windows),我可以将其更改为转到文件吗?(命令提示符上没有显示任何内容)。

除了@Bryan的建议外,如果您想将输出(xml、日志、报告)重定向到特定目录或文件,您可以对
pybot
脚本使用以下选项:

-d --outputdir dir       Where to create output files. The default is the
                      directory where tests are run from and the given path
                      is considered relative to that unless it is absolute.
-o --output file         XML output file. Given path, similarly as paths given
                      to --log, --report, --xunit, and --debugfile, is
                      relative to --outputdir unless given as an absolute
                      path. Other output files are created based on XML
                      output files after the test execution and XML outputs
                      can also be further processed with Rebot tool. Can be
                      disabled by giving a special value `NONE`. In this
                      case, also log and report are automatically disabled.
                      Default: output.xml
-l --log file            HTML log file. Can be disabled by giving a special
                      value `NONE`. Default: log.html
                      Examples: `--log mylog.html`, `-l NONE`
-r --report file         HTML report file. Can be disabled with `NONE`
                      similarly as --log. Default: report.html

也许您只是想将其记录到您的控制台(对于Jenkins):

或者有时检查机器人测试的调试是很好的:

-b --debugfile file      Debug file written during execution. Not created
                         unless this option is specified.

在linux服务器上,您可以通过管道将robot命令行传输到tee

robot -d results <test name>.robot  | tee <test name>.out
robot-d结果。robot|tee.out

如果从代码运行,可以执行以下操作

import robot.run
with open("message_out.log", "w") as log_file_out, open("message_err.log", "w") as log_file_err:
    robot.run("test",
               stdout=log_file_out,
               stderr=log_file_err)

您是否尝试了重定向输出的常规方法<代码>机器人…>console.txt?嗨,布莱恩,我想这就是我需要的,尽管我还没有试过。我的目的是将控制台输出显示到日志仪表板,类似于Jenkins在其控制台输出中所做的操作。我稍后会试试这个。非常感谢!你好,Daemon12。谢谢你。然而,我已经知道Robot框架有这个功能。我想要的是实时捕获控制台输出并将其显示在日志仪表板中(类似于Jenkins在控制台日志中所做的)。我想Bryan的评论就是我想要的。:-)谢谢
import robot.run
with open("message_out.log", "w") as log_file_out, open("message_err.log", "w") as log_file_err:
    robot.run("test",
               stdout=log_file_out,
               stderr=log_file_err)