I have some C++ code that uses Qt's QProcess to run an scp command in Linux, but I never get any output from the process:
void CopyClass::CopyClass()
{
mpScpProcess = new QProcess(this);
connect(mpScpProcess, SIGNAL(finished(int)), this, SLOT(onCopyFinished(int)));
connect(mpScpProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadCopyOutput()));
}
void CopyClass::startScp()
{
mpScpProcess->setProcessChannelMode(QProcess::MergedChannels);
mpScpProcess->start("scp 192.168.1.100:/file.txt ./");
}
void CopyClass::onCopyFinished(int val)
{
qWarning("Copy Finished");
}
void CopyClass::onReadCopyOutput()
{
QString output = mpScpProcess->readAll().data();
qWarning("Output: %s", qPrintable(output));
}
onCopyFinished gets called, and the scp copy succeeds, but no output ever comes out (onReadCopyOutput is never called). But I know it should output something like this:
file.txt 100% 1KB 1.9MB/s 00:00
Anyone know why it's not working? Thanks.
scp does not generate output when its standard output is being redirected to a pipe:
You'll see that
out.txt
is empty. I don't think there's much you can do about it.