1

I'm wondering if it's possible to read what's happening in Windows console live and either store it in a log/text file or store as a string of some sort as it runs.

Below is an example of some of the information that is displayed. In this case it's stating what is happening on a django/python webpage it is running:

[27/Feb/2016 14:51:50] "GET /color_liker/static/color_ajax_switch.js HTTP/1.1" 404 1697
[27/Feb/2016 14:51:52] "GET /color_liker/search/?color_search_text=th HTTP/1.1" 200 93
[27/Feb/2016 14:51:53] "GET /color_liker/search/?color_search_text=thi HTTP/1.1" 200 94
[27/Feb/2016 14:51:53] "GET /color_liker/search/?color_search_text=this HTTP/1.1" 200 95
[27/Feb/2016 14:51:54] "GET /color_liker/search/?color_search_text=this HTTP/1.1" 200 95
[27/Feb/2016 14:51:54] "GET /color_liker/search/?color_search_text=this+i HTTP/1.1" 200 97
[27/Feb/2016 14:51:55] "GET /color_liker/search/?color_search_text=this+is HTTP/1.1" 200 98
[27/Feb/2016 14:51:55] "GET /color_liker/search/?color_search_text=this+is HTTP/1.1" 200 98
[27/Feb/2016 14:51:55] "GET /color_liker/search/?color_search_text=this+is+a HTTP/1.1" 200 100
[27/Feb/2016 14:51:56] "GET /color_liker/search/?color_search_text=this+is+a HTTP/1.1" 200 100
[27/Feb/2016 14:51:56] "GET /color_liker/search/?color_search_text=this+is+a+t HTTP/1.1" 200 102
[27/Feb/2016 14:51:57] "GET /color_liker/search/?color_search_text=this+is+a+te HTTP/1.1" 200 103
[27/Feb/2016 14:51:57] "GET /color_liker/search/?color_search_text=this+is+a+tes HTTP/1.1" 200 104
[27/Feb/2016 14:51:58] "GET /color_liker/like_color_3/ HTTP/1.1" 200 46
[27/Feb/2016 14:51:59] "GET /color_liker/like_color_6/ HTTP/1.1" 200 45
[27/Feb/2016 14:52:00] "GET /color_liker/like_color_1/ HTTP/1.1" 200 45
[27/Feb/2016 14:52:01] "GET /color_liker/like_color_2/ HTTP/1.1" 200 45
[27/Feb/2016 14:52:03] "GET /color_liker/search/?color_search_text=this+is+a+test HTTP/1.1" 200 105

Basically, once able to read the file, I'd ideally be able to parse out the information I'm actually looking for, but I'm unsure of how to get to that stage.

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
MBP
  • 17
  • 6
  • 1
    Possible duplicate of [Redirect stdout to a file in Python?](http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python) – dot.Py Feb 27 '16 at 14:59
  • Are you getting all this information after you typed some command ? –  Feb 27 '16 at 15:00
  • It's possible to attach to a console and call [`ReadConsoleOutput`](https://msdn.microsoft.com/en-us/library/ms684965) to read the ouput buffer. But that's probably overkill for your needs. – Eryk Sun Feb 27 '16 at 15:05
  • I've had a look at that Redirect and I'm not sure if it applies to mine? noob: Yes, I have entered the command now it is just running (it can no longer be edited) – MBP Feb 27 '16 at 15:20
  • Have you tried reading about powershell filters and pipes? – GLaDOS Feb 27 '16 at 15:43
  • This is an example of an XY problem. You don't care about reading the output from the console; you care about getting this specific output in a log file. So, the actual question is: how do you get the Django development server to log to a file? – Daniel Roseman Feb 27 '16 at 17:09
  • @Daniel Roseman I've tried this but from what I've found and read if the server is in debug mode it will only give a blank log file. – MBP Feb 28 '16 at 11:08
  • Note that the current development version [has a change](https://docs.djangoproject.com/en/dev/releases/1.10/#runserver-output-goes-through-logging) which makes devserver output go through the logging module, so you can configure it to go wherever you like. – Daniel Roseman Feb 28 '16 at 12:22

0 Answers0