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()
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Alternative to system()

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 2 Posters 1.3k 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.
  • L Offline
    L Offline
    LxeA
    wrote on 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
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on 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
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on 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 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

          • Login

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