久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='XfHWx'></bdo><ul id='XfHWx'></ul>
      <i id='XfHWx'><tr id='XfHWx'><dt id='XfHWx'><q id='XfHWx'><span id='XfHWx'><b id='XfHWx'><form id='XfHWx'><ins id='XfHWx'></ins><ul id='XfHWx'></ul><sub id='XfHWx'></sub></form><legend id='XfHWx'></legend><bdo id='XfHWx'><pre id='XfHWx'><center id='XfHWx'></center></pre></bdo></b><th id='XfHWx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='XfHWx'><tfoot id='XfHWx'></tfoot><dl id='XfHWx'><fieldset id='XfHWx'></fieldset></dl></div>

      <tfoot id='XfHWx'></tfoot>

      1. <legend id='XfHWx'><style id='XfHWx'><dir id='XfHWx'><q id='XfHWx'></q></dir></style></legend>
      2. <small id='XfHWx'></small><noframes id='XfHWx'>

        Python 子進程模塊在段錯誤時不返回標準輸出

        Python subprocess module does not return stdout on segfault(Python 子進程模塊在段錯誤時不返回標準輸出)

        <small id='046dX'></small><noframes id='046dX'>

        • <i id='046dX'><tr id='046dX'><dt id='046dX'><q id='046dX'><span id='046dX'><b id='046dX'><form id='046dX'><ins id='046dX'></ins><ul id='046dX'></ul><sub id='046dX'></sub></form><legend id='046dX'></legend><bdo id='046dX'><pre id='046dX'><center id='046dX'></center></pre></bdo></b><th id='046dX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='046dX'><tfoot id='046dX'></tfoot><dl id='046dX'><fieldset id='046dX'></fieldset></dl></div>
            <bdo id='046dX'></bdo><ul id='046dX'></ul>

            <legend id='046dX'><style id='046dX'><dir id='046dX'><q id='046dX'></q></dir></style></legend>

                <tbody id='046dX'></tbody>

                <tfoot id='046dX'></tfoot>

                1. 本文介紹了Python 子進程模塊在段錯誤時不返回標準輸出的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在從 Python 運行一個 C 可執行文件,這個可執行文件有時會出現段錯誤.當它發生段錯誤時,子進程模塊不會在 stdout 或 stderr 中返回任何內容.

                  I'm running a C executable from Python and this executable sometimes segfaults. When it segfaults the subprocess module does not return anything in stdout or stderr.

                  示例代碼:

                  import subprocess
                  
                  proc = subprocess.Popen(['./a.out'], stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                  out, err = proc.communicate()
                  print 'out: "%s"' % out
                  print 'err: "%s"' % err
                  print proc.returncode
                  

                  a.out的來源是:

                  int main() {
                      printf("hello world
                  ");
                      int x = 1 / 0;
                  }
                  

                  ./a.out的輸出是:

                  hello world
                  Floating point exception
                  

                  Python 代碼的輸出是(在 Linux 中,python 2.7):

                  The output of the Python code is (in Linux, python 2.7):

                  out: ""
                  err: ""
                  -8
                  

                  有沒有辦法在可執行文件崩潰的情況下獲取它的輸出?

                  Is there a way to get the output of the executable even if it crashes?

                  將返回碼轉換為字符串消息的通用方法也不錯.

                  A generic method to translate returncode to a string message, would also be nice.

                  推薦答案

                  你的 C 程序沒有刷新它的輸出緩沖區.解決此問題的最簡單方法是將 STDOUT 的輸出模式更改為無緩沖:

                  Your C program is not flushing its output buffer. The easiest way around this problem is to change the output mode of STDOUT to unbuffered:

                  #include <stdio.h>
                  int main(int argc,char **argv) {
                      setvbuf(stdout,_IONBF,0,0);
                      printf("hello world
                  ");
                      int x = 1 / 0;
                  }
                  

                  現在您的程序(我對其進行了編輯以修復錯字)產生了正確的輸出:

                  Now your program (which I edited to fix a typo) produces the correct output:

                  $ python2.7 x.py
                  out: "hello world
                  "
                  err: ""
                  0
                  $
                  

                  在我的 Mac 上返回碼是 0,令人困惑,因為因信號而終止的程序沒有返回碼.

                  The return code is 0 on my Mac, confusingly, because programs that are terminated for a signal don't have a return code.

                  這篇關于Python 子進程模塊在段錯誤時不返回標準輸出的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                  • <bdo id='ztuPQ'></bdo><ul id='ztuPQ'></ul>

                      <tfoot id='ztuPQ'></tfoot>

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

                    • <i id='ztuPQ'><tr id='ztuPQ'><dt id='ztuPQ'><q id='ztuPQ'><span id='ztuPQ'><b id='ztuPQ'><form id='ztuPQ'><ins id='ztuPQ'></ins><ul id='ztuPQ'></ul><sub id='ztuPQ'></sub></form><legend id='ztuPQ'></legend><bdo id='ztuPQ'><pre id='ztuPQ'><center id='ztuPQ'></center></pre></bdo></b><th id='ztuPQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ztuPQ'><tfoot id='ztuPQ'></tfoot><dl id='ztuPQ'><fieldset id='ztuPQ'></fieldset></dl></div>

                          <legend id='ztuPQ'><style id='ztuPQ'><dir id='ztuPQ'><q id='ztuPQ'></q></dir></style></legend>
                            <tbody id='ztuPQ'></tbody>
                            主站蜘蛛池模板: 久久噜噜噜精品国产亚洲综合 | 亚洲天堂中文字幕 | 欧美日韩一二区 | 五十女人一级毛片 | 国产专区在线 | 99pao成人国产永久免费视频 | 国产精品网址 | 亚洲中午字幕 | 91精品在线播放 | 国产a区| 天堂av中文在线 | 亚洲一区二区三区免费在线观看 | 日本欧美国产在线 | 日韩黄 | 国产精品久久久久久久午夜 | 中文av网站| 亚洲天堂久久 | 亚洲二区在线观看 | 久久69精品久久久久久国产越南 | 成人在线观看免费观看 | 久久成人午夜 | 久久国产精品99久久久久 | 超碰成人免费 | 91资源在线观看 | 久久精品这里精品 | 欧美日韩国产免费 | 又爽又黄axxx片免费观看 | 国产在线一区二区三区 | 亚洲欧美日韩在线不卡 | 午夜a√ | 欧美精品成人一区二区三区四区 | 久久久久国产精品一区二区 | www狠狠爱com | 草久久免费视频 | 91麻豆精品国产91久久久久久久久 | 99精品国产一区二区三区 | 国产一区二区三区日韩 | 先锋av资源网 | 成人午夜激情 | 国产精品国产成人国产三级 | 91视频在线观看 |