Reputation: 11
I have a python script which will be run as a Visual Studio post build event. That script will run around 1 minute or even longer. The python script itself will print some messages to console to indicate the progress during the execution, but I can only see those messages in Visual Studio build output window after the whole script was finished. I want a way to show the progress messages in VS output window so that i can know the progress of the script.
I tried to use "start /wait python myScript.py" in the post build event, that will launch a new console window with all the progress messages during the execution and it will be automatically closed once finished, but if there's some failure happened, i want to see where the failure is in the build output window, or at least the new console window will not be closed so that user can check (not perfect, but is acceptable).
Why didn't VS provide a way to display the intermediate console messages for build event script as when we build the source code?
Is there a way to achieve what I need?
Thanks in advance.
Upvotes: 0
Views: 191
Reputation: 11
For people who met similar issue, python "print" method will use buffered I/O by default (it also has a parameter to control if it will be flushed), we can add "-u" parameter when running python script to force to use unbuffered stdout/stderr. So, the solution is run python script in your build event as "python -u script.py". Simple solution:). Also, if you are using logging module to print to console, there would be no such problem, since logging is using unbuffered stdout/stderr by default.
Upvotes: 0