2

In Django I need to run a shell command at some point. The command takes 6-10 minutes so I like to get live stdout from the command in my Django View in order to live track the command.

I now how to run the command and get live output with subprocess but I have no clue of how to pass the live output to the views.

1
  • I think your question was ok. Didn't need to remove it. It could help others. Commented Feb 19, 2021 at 9:11

1 Answer 1

1

I would suggest running the sub process into cron and storing the output to a file/db where you can get the progress from the view. Another option is to go for threading using celery.

The problem is that the view is not persistent, so you can not keep the hook to the output pipe across http requests.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer ! So if i run my command and redirect stdout in a file I will be able to get the file content in live from my view ?
yes. provided you import os, you can use file operations and render the output into your html

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.