import subprocess as sp print(sp.check_output( args=['python', '-c', 'print("Spam")'], # read errors too stderr=sp.STDOUT ))