diff --git a/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.h b/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.h index 2dd0b4e2f994c3962ac5d8b21baa46a2a9ce5c37..9cbf761b4c12b5fec6f9309ee6ab38ddfe5cf0f8 100644 --- a/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.h +++ b/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.h @@ -93,6 +93,10 @@ private: int m_StarsCount; int m_CurrentNbStars; + + bool m_CoutIsConsole; + + std::string m_Buffer; }; } // end namespace otb diff --git a/Modules/Core/Common/src/otbStandardOneLineFilterWatcher.cxx b/Modules/Core/Common/src/otbStandardOneLineFilterWatcher.cxx index 7baeaaef4c7df8f4c427d85c0dfc67fefbc81b65..01bde86ca79f6cfc01bb040ee91692628dabc3c4 100644 --- a/Modules/Core/Common/src/otbStandardOneLineFilterWatcher.cxx +++ b/Modules/Core/Common/src/otbStandardOneLineFilterWatcher.cxx @@ -24,6 +24,7 @@ #include "otbStandardOneLineFilterWatcher.h" #include "otbStopwatch.h" +#include "otbSystem.h" namespace otb { @@ -31,7 +32,8 @@ namespace otb StandardOneLineFilterWatcher ::StandardOneLineFilterWatcher() : m_StarsCount(50), - m_CurrentNbStars(-1) + m_CurrentNbStars(-1), + m_CoutIsConsole( System::IsInteractive(1) ) { } @@ -40,7 +42,8 @@ StandardOneLineFilterWatcher const char *comment) : FilterWatcherBase(process, comment), m_StarsCount(50), - m_CurrentNbStars(-1) + m_CurrentNbStars(-1), + m_CoutIsConsole( System::IsInteractive(1) ) { } @@ -49,7 +52,8 @@ StandardOneLineFilterWatcher const std::string& comment) : FilterWatcherBase(process, comment.c_str()), m_StarsCount(50), - m_CurrentNbStars(-1) + m_CurrentNbStars(-1), + m_CoutIsConsole( System::IsInteractive(1) ) { } @@ -82,12 +86,22 @@ StandardOneLineFilterWatcher { std::string stars(nbStars, '*'); std::string blanks(nbBlanks, ' '); - - std::cout << "\r" - << m_Comment - << ": " - << progressPercent << "% [" << stars << blanks << "]" - << std::flush; + if (m_CoutIsConsole) + { + std::cout << "\r" + << m_Comment + << ": " + << progressPercent << "% [" << stars << blanks << "]" + << std::flush; + } + else + { + std::ostringstream oss; + oss << m_Comment + << ": " + << progressPercent << "% [" << stars << blanks << "]"; + m_Buffer = oss.str(); + } } m_CurrentNbStars = nbStars; @@ -107,6 +121,12 @@ StandardOneLineFilterWatcher { m_Stopwatch.Stop(); + if (m_Process && !m_CoutIsConsole) + { + std::cout << m_Buffer; + m_Buffer = std::string(""); + } + std::cout << " ("; m_Stopwatch.GetElapsedHumanReadableTime(std::cout); std::cout << ")"