Qt - 如何执行此命令?

时间:2017-03-10 09:27:09

标签: c++ qt qprocess

我尝试使用此命令连接到服务器时自动接受主机密钥

QString cmd = QString("echo y | plink.exe -ssh %1 -i root.ppk -l root exit").arg(strSensorAddress)

当我从Windows中的cmd.exe启动它时,它正在运行。

我试图在Qt中这样做,但它不起作用:

QString cmd = QString("plink.exe -ssh %1 -i root.ppk -l root exit").arg(strSensorAddress);

process1.setStandardOutputProcess(&process2);

process1.start("echo y");
process2.start(cmd);
process2.setProcessChannelMode(QProcess::ForwardedChannels);

就像这样:

QStringList arguments;
arguments << "plink.exe" << "-ssh" << strSensorAddress << "-i" << "root.ppk" << "-l" << "root" << "exit";

process1.setStandardOutputProcess(&process2);
process1.start("echo y");
process2.start("cmd.exe", arguments);
process2.setProcessChannelMode(QProcess::ForwardedChannels);

0 个答案:

没有答案