Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there any sideeffects of using system command
Forum Updated to NodeBB v4.3 + New Features

Is there any sideeffects of using system command

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    guru007
    wrote on 21 Dec 2015, 09:09 last edited by
    #1

    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:Quimup

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

    1 Reply Last reply
    0
    • V Offline
      V Offline
      ValentinMichelet
      wrote on 21 Dec 2015, 15:15 last edited by
      #2

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

      So I would avoid approach 2, but I don't know what is best between approach 1 and 3.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 21 Dec 2015, 17:54 last edited by
        #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.

        Read and abide by the Qt Code of Conduct

        G 1 Reply Last reply 22 Dec 2015, 09:05
        0
        • K kshegunov
          21 Dec 2015, 17:54

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

          G Offline
          G Offline
          guru007
          wrote on 22 Dec 2015, 09:05 last edited by
          #4

          @kshegunov
          thanks for your valuable replies.........

          1 Reply Last reply
          0

          1/4

          21 Dec 2015, 09:09

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved