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

Is there any sideeffects of using system command

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.2k Views
  • 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 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
    • ValentinMicheletV Offline
      ValentinMicheletV Offline
      ValentinMichelet
      wrote on 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
      • kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on 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
        0
        • kshegunovK kshegunov

          @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 last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

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