diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e9faf68..3df8ab25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Fix crash on startup with Browser as the initial screen. * Show the Visualizer immediately if it's the initial screen. * Draw a separator between albums with the same name, but a different artist. +* Suppress output of all external commands. # ncmpcpp-0.9 (2020-12-20) * Fix various Mopidy specific bugs. diff --git a/src/macro_utilities.cpp b/src/macro_utilities.cpp index 6cd05550..88c3c923 100644 --- a/src/macro_utilities.cpp +++ b/src/macro_utilities.cpp @@ -87,8 +87,7 @@ RunExternalCommand::RunExternalCommand(std::string &&command) void RunExternalCommand::run() { - GNUC_UNUSED int res; - res = std::system(("nohup " + m_command + " >/dev/null 2>&1 &").c_str()); + runExternalCommandNoOutput(m_command, false); } RunExternalConsoleCommand::RunExternalConsoleCommand(std::string &&command) @@ -102,10 +101,23 @@ RunExternalConsoleCommand::RunExternalConsoleCommand(std::string &&command) void RunExternalConsoleCommand::run() { - GNUC_UNUSED int res; - NC::pauseScreen(); - res = std::system(m_command.c_str()); - NC::unpauseScreen(); + runExternalConsoleCommand(m_command); } } + +void runExternalConsoleCommand(const std::string &cmd) +{ + NC::pauseScreen(); + std::system(cmd.c_str()); + NC::unpauseScreen(); +} + +void runExternalCommandNoOutput(const std::string &cmd, bool block) +{ + if (block) + std::system((cmd + " >/dev/null 2>&1").c_str()); + else + std::system(("nohup " + cmd + " >/dev/null 2>&1 &").c_str()); + +} diff --git a/src/macro_utilities.h b/src/macro_utilities.h index 0e6168d7..0dc34dd5 100644 --- a/src/macro_utilities.h +++ b/src/macro_utilities.h @@ -82,4 +82,9 @@ private: } +// Helpers + +void runExternalConsoleCommand(const std::string &cmd); +void runExternalCommandNoOutput(const std::string &cmd, bool block); + #endif // NCMPCPP_MACRO_UTILITIES_H diff --git a/src/screens/lyrics.cpp b/src/screens/lyrics.cpp index c2cc7d74..17754e97 100644 --- a/src/screens/lyrics.cpp +++ b/src/screens/lyrics.cpp @@ -34,6 +34,7 @@ #include "format_impl.h" #include "global.h" #include "helpers.h" +#include "macro_utilities.h" #include "screens/lyrics.h" #include "screens/playlist.h" #include "settings.h" @@ -323,24 +324,15 @@ void Lyrics::edit() Statusbar::print("Opening lyrics in external editor..."); - GNUC_UNUSED int res; - std::string command; std::string filename = lyricsFilename(m_song); escapeSingleQuotes(filename); if (Config.use_console_editor) { - command = Config.external_editor + " '" + filename + "'"; - NC::pauseScreen(); - res = system(command.c_str()); - NC::unpauseScreen(); + runExternalConsoleCommand(Config.external_editor + " '" + filename + "'"); fetch(m_song); } else - { - command = "nohup " + Config.external_editor - + " '" + filename + "' > /dev/null 2>&1 &"; - res = system(command.c_str()); - } + runExternalCommandNoOutput(Config.external_editor + " '" + filename + "'", false); } void Lyrics::toggleFetcher() diff --git a/src/status.cpp b/src/status.cpp index 6af5e621..28e783c9 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -28,6 +28,7 @@ #include "format_impl.h" #include "global.h" #include "helpers.h" +#include "macro_utilities.h" #include "screens/lyrics.h" #include "screens/media_library.h" #include "screens/outputs.h" @@ -489,9 +490,9 @@ void Status::Changes::playerState() } throw std::logic_error("unreachable"); }; - GNUC_UNUSED int res; setenv("MPD_PLAYER_STATE", stateToEnv(m_player_state), 1); - res = system(Config.execute_on_player_state_change.c_str()); + // Since we're setting a MPD_PLAYER_STATE, we need to block. + runExternalCommandNoOutput(Config.execute_on_player_state_change, true); unsetenv("MPD_PLAYER_STATE"); } @@ -568,9 +569,8 @@ void Status::Changes::songID(int song_id) const auto &s = it != pl.endV() ? *it : Mpd.GetCurrentSong(); if (!s.empty()) { - GNUC_UNUSED int res; if (!Config.execute_on_song_change.empty()) - res = system(Config.execute_on_song_change.c_str()); + runExternalCommandNoOutput(Config.execute_on_song_change, false); if (Config.fetch_lyrics_in_background) myLyrics->fetchInBackground(s, false);