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

QProcess: Start, interact and keep running when Application exits

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 760 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.
  • T Offline
    T Offline
    themts
    wrote on 3 Jan 2022, 07:54 last edited by
    #1

    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.

    J 1 Reply Last reply 3 Jan 2022, 08:14
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 3 Jan 2022, 07:59 last edited by
      #2

      @themts said in QProcess: Start, interact and keep running when Application exits:

      As soon as I quit my application I need to keep the openvpn-connection active

      This doesn't make sense to me. How do you know that the connection is (not) open when you start your application the next time?

      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
      • T Offline
        T Offline
        themts
        wrote on 3 Jan 2022, 08:00 last edited by
        #3

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

        1 Reply Last reply
        0
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 3 Jan 2022, 08:09 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 3 Jan 2022, 08:15
          0
          • T themts
            3 Jan 2022, 07:54

            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.

            J Offline
            J Offline
            JonB
            wrote on 3 Jan 2022, 08:14 last edited by JonB 1 Mar 2022, 08:14
            #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 3 Jan 2022, 08:21
            1
            • C Christian Ehrlicher
              3 Jan 2022, 08:09

              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 3 Jan 2022, 08:15 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
              • C Online
                C Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 3 Jan 2022, 08:20 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
                • J JonB
                  3 Jan 2022, 08:14

                  @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 3 Jan 2022, 08:21 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.

                  J 1 Reply Last reply 3 Jan 2022, 08:26
                  0
                  • C Online
                    C Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 3 Jan 2022, 08:24 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
                      3 Jan 2022, 08:21

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

                      J Offline
                      J Offline
                      JonB
                      wrote on 3 Jan 2022, 08:26 last edited by JonB 1 Mar 2022, 08:28
                      #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 3 Jan 2022, 08:52 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

                        J 1 Reply Last reply 3 Jan 2022, 08:58
                        0
                        • T themts
                          3 Jan 2022, 08:52

                          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

                          J Offline
                          J Offline
                          JonB
                          wrote on 3 Jan 2022, 08:58 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

                          1/12

                          3 Jan 2022, 07:54

                          • Login

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