Suppress output of all external commands

This commit is contained in:
Andrzej Rybczak
2020-12-21 19:43:40 +01:00
parent 89ebfbf73d
commit f3fe45f3ff
5 changed files with 31 additions and 21 deletions

View File

@@ -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.

View File

@@ -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());
}

View File

@@ -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

View File

@@ -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()

View File

@@ -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);