Redirect using freopen

This commit is contained in:
Rico Tiongson 2020-04-18 03:01:23 +08:00
parent 94858c63fe
commit 3a9d6c26ed

View File

@ -20,9 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <unistd.h> // popen, pclose #include <cstdio> // freopen, stdout
#include <memory> // std::unique_ptr
#include <cstdlib> // std::system
#include "../all_headers.hpp" #include "../all_headers.hpp"
namespace comfortable_swipe::service namespace comfortable_swipe::service
@ -32,10 +30,12 @@ namespace comfortable_swipe::service
*/ */
void restart() void restart()
{ {
// stop, while redirecting stdout to pipe // dont show stdout on stop
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(__COMFORTABLE_SWIPE__PROGRAM__ " stop", "r"), pclose); freopen("/dev/null", "a", stdout);
comfortable_swipe::service::stop();
// restart service // show back on start
freopen ("/dev/tty", "a", stdout);
comfortable_swipe::service::start(); comfortable_swipe::service::start();
} }
} }