Solved Weird behavior of QProcess and multiple qoutes
-
@Manta-Ray You need to pass 4 arguments to wpa_cli:
set_network, 0, psk, "12345678"
instead you passed 6
set_network, 0, psk, ", 12345678, "
-
@Manta-Ray No magic. You simply put both " as own parameters:
arguments << "set_network" << "0" << "psk" << "'\"" << pwd << "\"'";
see here:
("set_network", "0", "psk", "'\"", "12345678", "\"'")
Instead you need to put your password as one string with leading and trailing ", like here:
arguments << "set_network" << "0" << "psk" << "\"" + pwd + "\"";
-
Ahaaaa, Thanks you guys a lot!!!!!!
I really appreciate you!!!! -
@Manta-Ray
I met the same issue and it failed.
Could you show me your codes or tell me what's wrong with my codes following, thanksQString strSSID = "12345678" QString program = "wpa_cli"; QStringList arguments; arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << "'\"" << strSSID << "\"'"; QProcess prcsWlan4; prcsWlan4.start(program, arguments); prcsWlan4.waitForFinished(-1); QString strResult4 = prcsWlan4.readAllStandardOutput();
the result strResult4 is FAIL
-
@Guanhong said in Weird behavior of QProcess and multiple qoutes:
<< "'"" << strSSID << ""'";
Why do you quote this? It's not needed at all - every value in the QStringList is passed as one parameter to your app. That's the reason why you should not use the other call - to avoid useless and wrong quotes.
-
@Christian-Ehrlicher
thank you for your swift replyactually in my project, strSSID is a variable, it is delivered by other parameters, here I just made it a constant for convenience.
I changed
arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << "'"" << strSSID << ""'";
to
arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << "'"" + strSSID + ""'";it still FAILed.
could you help me? -
@Guanhong Please read once more what @Christian-Ehrlicher wrote. Your change is NOT what he wrote...
-
@jsulm thank you.
I think quotes are necessary, because there is a single quote outside a double quote.
I need to process the following command by QProcess, could you show me how?
pa_cli -i wlan0 set_network 1 ssid '"hima24g"' -
Again: there is no need to quote an argument when using QProcess::start() with QStringList - they are only needed on the command line so bash/cmd.exe/whatever knows what a single argument is! Your ssid is
hima24g
and not"hima24g"
or'hima24g'
... or? -
@Christian-Ehrlicher
Even if there are single quotes and double quotes in the command, is there no need to add quotes? I looked at earlier replies, it seems that quotes are need.I just removed quotes and changed my codes to
arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << strSSID ;
FAILed too. -
@Guanhong Then add proper error handling and also read from std error of your process to see whether it prints any errors.
-
@jsulm
QString strResult4 = prcsWlan4.readAllStandardOutput();
strResult4 is FAIL -
@Guanhong said in Weird behavior of QProcess and multiple qoutes:
readAllStandardOutput()
I was talking about std ERROR (https://doc.qt.io/qt-5/qprocess.html#readAllStandardError)...
-
Please run it on the command line. Maybe you don't have the proper privileges.
-
@Christian-Ehrlicher
I have run it on the command line, it is no problem. -
@Guanhong Please show how you run it on the command line
-
@Guanhong said in Weird behavior of QProcess and multiple qoutes:
<
wpa_cli -i wlan0 set_network 1 ssid '"hima24g"'
I run it on an Ubuntu console, and it can run successfully -
@Guanhong said in Weird behavior of QProcess and multiple qoutes:
wpa_cli -i wlan0 set_network 1 ssid '"hima24g"'
wpa_cli -i wlan0 set_network 1 ssid hima24g
should work just as good
-
set_network 1
is not
"set_network" << "0"
-
wpa_cli -i wlan0 set_network 1 ssid hima24g
without quotes, it does not work on my console.set_network 1 or set_network 0 does not matter.
It depends.