Avatar ·

Redirecting terminal output into a variable

📁 Advanced Python Topics, question, example

Help me understand how to redirect CMD output to a variable, because the variable is assigned only the exit code of the process. For clarity, here are a couple of examples:

import sys, os
command = ""Tasklist""
result1 = os.system(command)
print(result1) # at the output 0

Example 2

command = ""Tasklist > temp.txt""
result2 = os.system(command)
print(result2) # at the output 0
with