Is there any sideeffects of using system command
-
I want to control Media Player Daemon(mpd) with QT. To change songs I am using mpc which is commandline client for mpd. So my question is If I run mpc commands through system() command in Qt in another QProcess Is there any disadvantages of doing this.
Approach1:
QProcess new_command;
new_command.startDetached("mpc play 1");
Approach2:
system("mpc play 1");Approach3:
using mpd dev library to run functions directly from application as done in quimp application which is built in qt5.
Link:http://mpd.wikia.com/wiki/Client:QuimupPlease give me your expert view which approach is best.Using whole API is very difficult for me now because I am newbie in C++ and qt.
-
I read in several places that using system is not recommended.
http://www.cplusplus.com/forum/articles/11153/
https://en.wikipedia.org/wiki/Code_injection#Shell_injection
http://stackoverflow.com/questions/4622693/issuing-system-commands-in-linux-from-c-cSo I would avoid approach 2, but I don't know what is best between approach 1 and 3.
-
@guru007
QProcess::startDetached is a static function and doesn't need an object. So, you're usually encouraged to use it like this:QProcess::startDetached("mpc play 1");
system
is very specific platformwise, that's why you're advised not to use it, otherwise you might need to handle OS-specifics.
Using the library directly (if possible) would be my choice. But you could certainly go with controlling an external process as well. The drawback of approach 1 is that you still have to ensure (broadly speaking) that the mpc program you're using exists on the user machine (it's true for approach 3 as well, because you depend on an external library that must be installed for your program to work). Either way is viable, though, so it depends on your preference.Kind regards.