0

guys.I want to use Flask that runs a shell script and displays its output in a web page. The thing is when I run the script, i want the page to display the output of every command in that script so that the user can see the process of the shell script in the web page.I have tried to use os.popen('/myscript.sh').read(),but this command will only display the final output after the whole script is finished which is not I want.

Is there a way to do that?

NathanXu
  • 1
  • 1
  • Is there a way? Sure. Look into long-polling. Websockets are a pretty reasonable way to handle this on the transit end too. If you just want someone to hand you prewritten code... that might be a bit too much of a request, especially if you expect a prewritten answer that covers both ends (that is, including the JavaScript side incrementally receiving and displaying updates). – Charles Duffy Jul 07 '18 at 03:18
  • https://www.fullstackpython.com/websockets.html might be one place to start for background on the streaming part. – Charles Duffy Jul 07 '18 at 03:22
  • For an implementation of the Python subprocess end, take a look at the code being asked about at https://stackoverflow.com/questions/41431882/live-stream-stdout-and-stdin-with-websocket -- indeed, if you weren't asking the question narrowed to flask, I'd just call that an answer (and this a duplicate). – Charles Duffy Jul 07 '18 at 03:22

0 Answers0