如何使用QProcess进行命令行交互参数,我正在尝试传输一个文件usimg,该文件提示输入密码
QString program = "c:/temp/pscp.exe";
QStringList arguments;
arguments << "C:/Users/polaris8/Desktop/Test1GB.zip" << "Mrigendra@192.168.26.142:/home/";
QPointer<QProcess> myProcess;
myProcess = new QProcess;
connect(myProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
myProcess->start(program , arguments);在此之后,逗号行要求密码如何使用QProcess来满足它,我能否克服它,在我的参数中只为scp提供一些选项,或者我的插槽readOutput中向命令行抛出密码的代码应该是什么。任何建议都会有帮助。谢谢
发布于 2014-01-14 08:18:48
我认为您可以通过以下方式将用户名/密码作为选项传递:
-l user
-pw passwd所以你们的论点应该是这样的:
QStringList arguments;
arguments << "-l" << "Mrigendra" << "-pw" << "Password" <<
"C:/Users/polaris8/Desktop/Test1GB.zip" <<
"192.168.26.142:/home/";发布于 2014-01-14 07:53:18
scp似乎没有这样的选项,但是pscp (sftp客户端确实有)。因此,我将编写类似这样的东西,以便根据以下手册页扩展初始参数,并使用该选项
QString program = "c:/temp/pscp.exe";
QStringList arguments;
arguments << "-pw" << "password" << "C:/Users/polaris8/Desktop/Test1GB.zip" << "Mrigendra@192.168.26.142:/home/";
^^^^^^^^^^^^^^^^^^^
QPointer<QProcess> myProcess;
myProcess = new QProcess;
connect(myProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
myProcess->start(program , arguments);此外,我鼓励您使用QStandardPaths作为您的路径。详情请参阅文件:
QStandardPaths::DesktopLocation 0 Returns the user's desktop directory.因此,您最终可以替换此字符串:
"C:/Users/polaris8/Desktop/Test1GB.zip"有以下几点:
QStandardPaths::locate(QStandardPaths::DesktopLocation, "Test1GB.zip")尽管如此,您可能希望在将来考虑使用密钥而不是密码。它将更加安全,也方便您的应用程序。
https://stackoverflow.com/questions/21108197
复制相似问题