I\'m executing a .py file, which spits out a give string. This command works fine
execfile (\'file.py\')
But I want the output (in addition to it being shown
what your doing is checking the output of execfile('file.py') against the string 'output.txt'
execfile('file.py')
'output.txt'
you can do what you want to do with subprocess
#!/usr/bin/env python import subprocess with open("output.txt", "w+") as output: subprocess.call(["python", "./script.py"], stdout=output);