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

        • <bdo id='Aojui'></bdo><ul id='Aojui'></ul>

        <legend id='Aojui'><style id='Aojui'><dir id='Aojui'><q id='Aojui'></q></dir></style></legend>

      1. <i id='Aojui'><tr id='Aojui'><dt id='Aojui'><q id='Aojui'><span id='Aojui'><b id='Aojui'><form id='Aojui'><ins id='Aojui'></ins><ul id='Aojui'></ul><sub id='Aojui'></sub></form><legend id='Aojui'></legend><bdo id='Aojui'><pre id='Aojui'><center id='Aojui'></center></pre></bdo></b><th id='Aojui'></th></span></q></dt></tr></i><div id='Aojui'><tfoot id='Aojui'></tfoot><dl id='Aojui'><fieldset id='Aojui'></fieldset></dl></div>
        <tfoot id='Aojui'></tfoot>
      2. 从 python 调用外部程序并获取其输出

        时间:2023-07-21

        1. <i id='9t4L7'><tr id='9t4L7'><dt id='9t4L7'><q id='9t4L7'><span id='9t4L7'><b id='9t4L7'><form id='9t4L7'><ins id='9t4L7'></ins><ul id='9t4L7'></ul><sub id='9t4L7'></sub></form><legend id='9t4L7'></legend><bdo id='9t4L7'><pre id='9t4L7'><center id='9t4L7'></center></pre></bdo></b><th id='9t4L7'></th></span></q></dt></tr></i><div id='9t4L7'><tfoot id='9t4L7'></tfoot><dl id='9t4L7'><fieldset id='9t4L7'></fieldset></dl></div>
            <bdo id='9t4L7'></bdo><ul id='9t4L7'></ul>
                <tfoot id='9t4L7'></tfoot>

                <small id='9t4L7'></small><noframes id='9t4L7'>

                    <tbody id='9t4L7'></tbody>
                  <legend id='9t4L7'><style id='9t4L7'><dir id='9t4L7'><q id='9t4L7'></q></dir></style></legend>

                1. 本文介绍了从 python 调用外部程序并获取其输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想从 Python 调用一个用 C++ 编写并编译的程序 (.exe).可执行文件将两个文件作为输入并返回一个分数.

                  I want to call a program (.exe), which is written in C++ and compiled, from Python. The executable takes as input two files and returns a score.

                  我需要为多个文件执行此操作.所以,我想在 python 中编写一个小脚本,循环多个文件,将它们传递给可执行文件并取回值.

                  I need to do this for multiple files. So, I would like to write a small script in python which loops over multiple files, passes them to the executable and gets back the values.

                  现在,我已经完成了搜索,我知道 SWIG 和 Boost::Python 可能是一个选择,但我试图找到是否有更简单的方法.我不需要扩展"C++ 程序.我只是想像从命令行一样调用它并获取返回的数字.

                  Now, I have done my search and I know about SWIG and Boost::Python may be an option but I was trying to find if there is an easier way. I do not need to 'extend' the C++ program. I simply want to call it just like I would from a command line and get the returned number.

                  推荐答案

                  要运行外部程序并获取其输出,请使用 subprocess.check_output 在 Python 2.7+ 上.文档中的示例:

                  To run an external program and get its output, use subprocess.check_output on Python 2.7+. The example from the docs:

                  >>> subprocess.check_output(["ls", "-l", "/dev/null"])
                  'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null
                  '
                  

                  check_call 只是返回程序的返回码,而不是输出.

                  check_call just returns the return code of the program, not the output.

                  这篇关于从 python 调用外部程序并获取其输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从子程序到 pyQT Widget 的标准输出的实时输出 下一篇:如何使用 python 在多个终端窗口中运行多个文件

                  相关文章

                      <bdo id='8Holf'></bdo><ul id='8Holf'></ul>
                    1. <i id='8Holf'><tr id='8Holf'><dt id='8Holf'><q id='8Holf'><span id='8Holf'><b id='8Holf'><form id='8Holf'><ins id='8Holf'></ins><ul id='8Holf'></ul><sub id='8Holf'></sub></form><legend id='8Holf'></legend><bdo id='8Holf'><pre id='8Holf'><center id='8Holf'></center></pre></bdo></b><th id='8Holf'></th></span></q></dt></tr></i><div id='8Holf'><tfoot id='8Holf'></tfoot><dl id='8Holf'><fieldset id='8Holf'></fieldset></dl></div>

                      <small id='8Holf'></small><noframes id='8Holf'>

                      <legend id='8Holf'><style id='8Holf'><dir id='8Holf'><q id='8Holf'></q></dir></style></legend>
                    2. <tfoot id='8Holf'></tfoot>