Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt5 QProcess处理带“的参数;特别";人物_C++_Linux_Qt_Ftp - Fatal编程技术网

C++ Qt5 QProcess处理带“的参数;特别";人物

C++ Qt5 QProcess处理带“的参数;特别";人物,c++,linux,qt,ftp,C++,Linux,Qt,Ftp,我正在维护一个Qt5程序,该程序使用QProcess在Linux上执行ncftpget 我尝试执行的命令是: ncftpget-E-Z-u用户名-p'a#$b1379'1.1.1/x/y/temp/update/file 它只是将文件从服务器传输到本地目录。如果我在bash命令行上执行上述命令,它将正常工作 但是,当我的Qt5应用程序使用QProcess执行相同的命令时,ftp服务器答复说用户名/密码不正确。当密码不包含任何“特殊”字符时,它会正常工作 正如QProcess所述,它没有在shel

我正在维护一个
Qt5
程序,该程序使用
QProcess
Linux
上执行
ncftpget

我尝试执行的命令是:

ncftpget-E-Z-u用户名-p'a#$b1379'1.1.1/x/y/temp/update/file

它只是将文件从服务器传输到本地目录。如果我在bash命令行上执行上述命令,它将正常工作

但是,当我的
Qt5
应用程序使用
QProcess
执行相同的命令时,
ftp
服务器答复说用户名/密码不正确。当密码不包含任何“特殊”字符时,它会正常工作

正如
QProcess
所述,它没有在shell中执行命令。所以我假设
fork()
exec()
调用的某个版本被执行如何使
QProcess
在此处执行正确的操作?

我假设问题与密码中的特殊字符有关。当我构建我的
QProcess
参数列表时,我特别确保密码被
包围,以便对特殊字符进行转义

代码段:

processFTP.setParent(this->parent());
processFTP.setProcessChannelMode(QProcess::MergedChannels);

// ncftpArgs is a QStringList
// snippet doesn't show complete argument list

ncftpArgs->push_back("-Z");
ncftpArgs->push_back("-u");//username
ncftpArgs->push_back(QString((*phashSettings)[FTPUSERNAME]));
ncftpArgs->push_back("-p");//pw
// password can have special characters when shell executes command.
QString password((*phashSettings)[FTPPASSWORD]);
password.prepend("'");
password.append("'");
ncftpArgs->push_back(password);

ncftpArgs->push_back(QString((*phashSettings)[FTPSERVERIP]));
ncftpArgs->push_back(QString((*phashSettings)[FTPTEMPDIR]));

//beging the ncftpget session
QString sExe = "ncftpget";  //process name

// processFTP is a QProcess object
processFTP.start(sExe, (*ncftpArgs));
bSuccess = processFTP.waitForStarted();

// .... more code to monitor process etc...
代码记录了将传递给
processFTP
的命令和参数,一切看起来都是正确的

如何正确设置参数并启动
QProcess
对象,以便将包含特殊字符的密码参数正确传递给可执行文件
ncftpget

和/或如何调试问题?

当我构建我的QProcess参数列表时,我特别确保密码被“转义”包围,以便对特殊字符进行转义

不要在密码后面附加或加上
,请删除这些行

password.prepend("'");
password.append("'");

QProcess::start
负责程序参数的正确传递方式。此外,在代码中,bash解释器不是通过此调用运行的。

如果我将password参数保持原样,它将无法工作。我得到同样的结果-无法登录到ftp服务器,因为密码错误。如果没有调用bash shell,那么我假设QProcess执行某种类型的exec()调用?是的,它执行fork()和execve()。谢谢你,S.M.那么我该怎么做才能让
execve()
将带有“特殊字符”的参数传递给可执行文件?特殊字符不会被解释,按原样传递它们。如果您的Qt是使用
QPROCESS\u DEBUG
构建的,那么请尝试启用调试日志。为什么不使用QFtp类?为什么使用向下投票?