I'm trying to stream stdout of a script,
proc = subprocess.Popen(
for line in iter(proc.stdout.readline,''):
yield line.rstrip() + '<br/>\n'
return Flask.Response(inner(), mimetype='text/html')
subprocess.Popen(['dmesg'], shell=True, stdout=subprocess.PIPE)
if __name__ == '__main__':
* Running on http://0.0.0.0:7000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger pin code: 262-399-135
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
You are calling the
python executable, which will always start an interpreter. You likely need to call the executable that you're working with directly. I'm not super familiar with Flask, but I assume it's actually running a WSGI application, and if you're using a virtual environment or something, the shell you're opening won't know where that virtual Python is, since the path is set dynamically. Something like this will get the correct executable path:
import sys try: import uwsgi ex = os.path.join(uwsgi.opt['home'], 'bin/python') # or some default location except (ImportError, KeyError): ex = sys.executable
proc = subprocess.Popen( [ex, 'myscript.py'], shell=True, stdout=subprocess.PIPE )
Now, this might not really fix your issue. It also seems like the script is not being passed properly as a parameter to the shell. You might want to mess around with it in the default interpreter or something to double check that the command that it's calling is correct. Alternatively, you should be able to get away with not separating the parameters:
proc = subprocess.Popen( ['python myscript.py'], shell=True, stdout=subprocess.PIPE )