QProcess: Start, interact and keep running when Application exits
-
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.
-
@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?
-
But how do you can interact with the already started process in the case it's already running?
-
@themts
You must usestartDetached()
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.
-
@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.
-
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.
-
@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. -
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.
-
@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 fromQProcess::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. -
@themts
Assuming you do write a separate Qt "VPN spawner" application, you then have a choice if it helps: you can start thatstartDetached()
, or if you prefer for communication with it you can start it with normalstart()
and have it do thestartDetached()
when it starts the VPN process.