QProcess output not showing

南楼画角 提交于 2019-12-11 18:04:29

问题


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.


回答1:


scp does not generate output when its standard output is being redirected to a pipe:

scp src dest > out.txt

You'll see that out.txt is empty. I don't think there's much you can do about it.



来源:https://stackoverflow.com/questions/13773410/qprocess-output-not-showing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!