Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [SOLVED] Alternative to system()

[SOLVED] Alternative to system()

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 2 Posters 1.3k 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.
  • L Offline
    L Offline
    LxeA
    wrote on 28 Jul 2014, 06:57 last edited by
    #1

    Hi !

    I am looking for an alternative to system(), in order to execute a command line that looks like this :
    @ system("myexecutable -ip <ip address> -pw <password> -othercommand > text.txt"); @

    I tried to use QProcess for this, but I can't make it work.
    Does someone have an idea of something I could use instead, or maybe the correct syntax when using QProcess::execute ?

    Thank you !

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 28 Jul 2014, 08:20 last edited by
      #2

      On Windows, you need to use QProcess to launch cmd.exe, and then provide your command line through the /C parameter, like this:
      @
      QProcess::startDetached("cmd.exe /C myexecutable -ip <ip address> -pw <password> -othercommand > text.txt");
      @

      You need to experiment with using QStringList to pass arguments, it usually takes several tries to make it work.

      On Linux and Mac, the line you posted is correct and should work.

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 28 Jul 2014, 08:21 last edited by
        #3

        Oh sorry, I have missed the redirection. You need to use "QProcess::setStandardOutputFile":http://qt-project.org/doc/qt-5/qprocess.html#setStandardOutputFile (or process).

        (Z(:^

        1 Reply Last reply
        0
        • L Offline
          L Offline
          LxeA
          wrote on 28 Jul 2014, 08:25 last edited by
          #4

          Thank you !
          I will try this out.

          Edit : I had some trouble with setStandardOutputFile, so I did @QProcess::execute("cmd.exe /C myexecutable -ip <ip> -pw <pw> -othercommand > text.txt");@ and it works !
          I was missing the "cmd.exe /C" part.

          1 Reply Last reply
          0

          2/4

          28 Jul 2014, 08:20

          • Login

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