QProcess 输出未显示 [英] QProcess output not showing
问题描述
我有一些 C++ 代码使用 Qt 的 QProcess 在 Linux 中运行 scp 命令,但我从未从进程中获得任何输出:
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 被调用,并且 scp 复制成功,但没有输出输出(从不调用 onReadCopyOutput).但我知道它应该输出如下内容:
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 在其标准输出被重定向到管道时不生成输出:
scp does not generate output when its standard output is being redirected to a pipe:
scp src dest > out.txt
您会看到 out.txt
是空的.我认为您对此无能为力.
You'll see that out.txt
is empty. I don't think there's much you can do about it.
这篇关于QProcess 输出未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!