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. QProcess: Start, interact and keep running when Application exits
Forum Updated to NodeBB v4.3 + New Features

QProcess: Start, interact and keep running when Application exits

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 978 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.
  • T Offline
    T Offline
    themts
    wrote on last edited by
    #3

    QProcess p;
    p.start("pidof", QStringList({ processName}), QIODevice::ReadOnly);

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #4

      But how do you can interact with the already started process in the case it's already running?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      T 1 Reply Last reply
      0
      • T themts

        Hi guys,

        I need to start a openVpn-connection in linux.
        Therefore I want to use QProcess to start openvpn, pass some arguments, enter a passphrase, and get some info about the connection status.

        As soon as I quit my application I need to keep the openvpn-connection active, so I have to detach from that process. Any idea how to do it?

        When I use QProcess::startDetached, I can no longer interact with it.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #5

        @themts
        You must use startDetached() if you want a child process you spawn to outlive its parent.

        I don't know what you mean by " I can no longer interact with it". But if you intend to "re-connect" to an already-running process in future --- however you recognise that situation --- you cannot use channels like stdin/out/err, you must use some kind of IPC, like sockets/named pipes/shared memory.

        T 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          But how do you can interact with the already started process in the case it's already running?

          T Offline
          T Offline
          themts
          wrote on last edited by
          #6

          @Christian-Ehrlicher
          I no longer interact. I‘m just displaying „connected“ and the user is able to disconnect now.

          The situation is like that:
          For remote support, the user can click „start remote-support“. This starts a vpn connection. While establishing, it is showing „connecting“, on error it shows „failed: reason“, on connected it shows „connected“ and is displaying the remote IP.

          When I connect to that machine now, sometimes I have to quit the application. Of course I don’t want to interrupt the vpn-connection in this case.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #7

            You can start it detached and output the stdout/stderr of the app to a file which can be read in later on by your own app.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • JonBJ JonB

              @themts
              You must use startDetached() if you want a child process you spawn to outlive its parent.

              I don't know what you mean by " I can no longer interact with it". But if you intend to "re-connect" to an already-running process in future --- however you recognise that situation --- you cannot use channels like stdin/out/err, you must use some kind of IPC, like sockets/named pipes/shared memory.

              T Offline
              T Offline
              themts
              wrote on last edited by
              #8

              @JonB
              To start the vpn-connection, I need to enter a passphrase (that way steeling the cert is not enough to establish a connection).
              So normally I would start the process and use stdin, stdout,… to enter the passphrase and get all the connection-information openvpn is giving me.
              When I use startDetached, I cannot use stdin,… anymore.

              JonBJ 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #9

                Then write a wrapper application where you can communicate via some IPC mechanism which handles your vpn connection. You can start this helper app as detached from your real app then.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • T themts

                  @JonB
                  To start the vpn-connection, I need to enter a passphrase (that way steeling the cert is not enough to establish a connection).
                  So normally I would start the process and use stdin, stdout,… to enter the passphrase and get all the connection-information openvpn is giving me.
                  When I use startDetached, I cannot use stdin,… anymore.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #10

                  @themts
                  Then exactly as @Christian-Ehrlicher has just written. You will need to write your own wrapper program around starting your VPN connection, which is what you will invoke from QProcess::startDetached(). That can talk stdin/out/err to your VPN process and can talk IPC to your Qt program both initially and at future times.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    themts
                    wrote on last edited by
                    #11

                    I also had this in mind as plan-b if I cannot detach from a running process.
                    I think I‘ll just go that way.

                    Thanks guys

                    JonBJ 1 Reply Last reply
                    0
                    • T themts

                      I also had this in mind as plan-b if I cannot detach from a running process.
                      I think I‘ll just go that way.

                      Thanks guys

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #12

                      @themts
                      Assuming you do write a separate Qt "VPN spawner" application, you then have a choice if it helps: you can start that startDetached(), or if you prefer for communication with it you can start it with normal start() and have it do the startDetached() when it starts the VPN process.

                      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