I have 2 scripts script1.py
and script2.py
in the same folder ,script1.py calls script2.py using Popen(See code below for details),issue is that the prints coming from script2.py is not being captured in script1.py,print output
and print error
doesn't print a thing in the code below? what am I missing here? how do I capture the prints from script2.py?
script1.py
import subprocess
from subprocess import Popen, PIPE, STDOUT
def func1 ():
cmd = "python script2.py"
proc = Popen(cmd.split(' '), stdout=PIPE, stderr=PIPE)
(output, error) = proc.communicate()
print output
print error
func1()
print "Done.."
script2.py
import sys
print "ERROR:port not detected"
sys.exit(29)
OUTPUT:-
C:\Dropbox>python script1.py
ERROR:port not detected
Done..