簡體   English   中英

子進程沒有捕獲標准輸出

[英]subprocess not catching stdout

幾天以來我一直在試圖弄清楚為什么我的 subprocess.Popen 沒有捕捉到標准輸出。 也許這與子進程輸出文件的事實有關。 當我在沒有 output 文件的情況下運行子進程並且標准輸出(您會在終端上看到)被咳嗽時,我發現了這一點。 Can you please help me how to catch it in the scenario with the output file, so I dont want to catch the output from the file but only the terminal output, so running output. 非常感謝任何形式的幫助。

     command = "cnvkit.py call %s -o %s" % (file, output)
     process_call = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=sfs.path('cnv_app/call_CNS/'), universal_newlines=True)
stdout, stderr = process_call.communicate()
     if process_call.returncode and stderr:
          output_call = stdout
          output_err_call = stderr
     else:
          output_call = stdout 
          process_call.poll()
          response = {'output_call': output_call, 'output_err_call': output_err_call}

我的子進程正在返回一個警告,該警告顯然會發送到 stderr,並且由於我的process_call.returncode將返回 0,這對於 if 語句為 False,因此只捕獲了空的 stdout,這就是為什么我沒有得到 output。 當出現警告時,stdout 全部轉到 stderr 我有點失望。 是的,你是對的,你需要一個水晶球來回答這個問題,但是你幫我解決了我的問題:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM