I am trying to fetch the output of the
fortune_list = ["(?i)art","(?i)comp","(?i)cookie","(?i)drugs","(?i)education","(?i)ethnic","(?i)food"]
for i in range(len(fortune_list)):
cmd = ['fortune', fortune_list_reply[i]]
output = subprocess.Popen( cmd, stdout=subprocess.PIPE ).communicate()
"XXXI:\n\tThe optimum committee has no members.\nXXXII:\n\tHiring consultants to conduct studies can be an excellent means of\n\tturning problems into gold -- your problems into their gold.\nXXXIII:\n\tFools rush in where incumbents fear to tread.\nXXXIV:\n\tThe process of competitively selecting contractors to perform work\n\tis based on a system of rewards and penalties, all distributed\n\trandomly.\nXXXV:\n\tThe weaker the data available upon which to base one's conclusion,\n\tthe greater the precision which should be quoted in order to give\n\tthe data authenticity.\n\t\t-- Norman Augustine\n"
To coalesce the output strings of terminal into one, split the output at new lines and store them in a list.
sentence = "" cmd = ['fortune', fortune_list_reply[i]] output = subprocess.Popen( cmd, stdout=subprocess.PIPE ).communicate() output = output.split('\n') for string in output: string = string.split("\t") for substring in string: if len(substring) == 0: continue else: sentence = sentence + " " + substring