'Capture output from subprocess.Popen commands that execute further processes

SOLVED: User error.

I have a python program that must utilize some other proprietary scripts that I can't access/control. I launch the proprietary (bash) script using

logfile = open('/file', 'a')
proc = subprocess.Popen(['/path/to/script/script','argument'], stdout=logfile, stderr=logfile)
proc.wait()

Unfortunately, the bash script that I have to execute then executes a Java script and the output of that Java script is getting printed to my terminal instead of the logfile that I've specified in the subprocess.Popen call. I'm not sure how to specify that all output needs to go to the logfile because it seems that stdout and stderr are the only parameters to control the flow of output and should be catching it.

I've attempted using subprocess.PIPE and then proc.communicate but it still goes to the screen. I've also attempted shell=True but that still goes to the screen as well. I also set sys.stdout=logfile and sys.stderr=logfile but still, it goes to terminal.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source