Because undoInfo -q -pq didn’t return anything, and it has a # in each line it prints out, just like other maya commands. So I guess the print out goes to stderr ?
Why this code doesn’t work? It should capture the print out in f ? reference
from contextlib import contextmanager
@contextmanager
def stderr_redirector(stream):
old_stderr = sys.stderr
sys.stderr = stream
old_stdout = sys.stdout
sys.stdout = stream
try:
yield
finally:
sys.stderr = old_stderr
sys.stdout = old_stdout
import io
f=io.StringIO()
with stderr_redirector(f):
mc.undoInfo(q=1,pq=1)
print '-'*30
print f.getvalue()