嘿,我正在更新我的腳本,我已經改變os到現在的子進程,但我不知道如何檢查輸出?我想檢查它是空的還是它的內容。腳本只是執行其他程序或句子列表。檢查子進程的輸出python3
"""
Created on Sun Jan 8 18:52:57 2017
@author: MarcGrad
"""
import sys
import subprocess
syntax = '''
------------------------------------------------------------------------------------
Syntax: python find_by_sentence.py *file1.txt
*List of sentences (column of)
------------------------------------------------------------------------------------
'''
if len(sys.argv) != 1:
print(syntax)
sys.exit()
open_file = open(sys.argv[1],'r')
list_of_sentences = []
for sent in open_file:
list_of_sentences.append(sent.rstrip())
counter = 0
for word in list_of_sentences:
counter += 1
print(counter,word)
subprocess.check_output("esearch -db protein -query %s | efetch -format fasta >> results_seq.txt" % (word), shell = True)
print('done :)')
open_file.close()
它看起來好像是將輸出連接到文件(results_seq.txt),那麼爲什麼你期望它是任何輸出? 此外,'subprocess.check_output'的返回值是輸出,所以你可以做一些驗證(你也可以通過'stderr = subprocess.STDOUT'獲得stderr) –
只是想知道什麼時候給出的句子有沒有結果:) – MTG