How to detect when ssh connection (over a QProcess) has finished?

后端 未结 2 1507
清酒与你
清酒与你 2021-01-23 10:41

I am running an ssh tunnel from an application using a QProcess:

QProcess* process = new QProcess();
process->start(\"ssh\", QStringList()<<         


        
2条回答
  •  自闭症患者
    2021-01-23 11:24

    I had the same problem, but in my case ssh do not output anything - so I couldn't just wait for output. I'm also using ssh to setupt tunnel, so I used QTcpSocket:

    program = "ssh";
    arguments << m_host << "-N" << "-L" << QString("3306:%1:3306").arg(m_host);
    connect(tunnelProcess, &QProcess::started, this, &Database::waitForTunnel);
    tunnelProcess->start(program, arguments);
    

    waitForTunnel() slot:

    QTcpSocket sock;
    sock.connectToHost("127.0.0.1", 3306);
    if(sock.waitForConnected(100000))
    {
         sock.disconnectFromHost();
         openDatabaseConnection();
    }
    else
        qDebug() << "timeout";
    

    I hope this will help future people finding this question ;)

提交回复
热议问题