No content from readAll()
-
I'm trying to check existence of a file on an android device via the adb command. The attempt to grab the console output via command=readAll() returns empty every time.
@
QProcess *check_busybox2=new QProcess;
check_busybox2->setProcessChannelMode(QProcess::MergedChannels);
cstring = adb + " -s " + daddr+port + " shell ls /system/xbin/which";
check_busybox2->start(cstring);
check_busybox2->waitForFinished(-1);
command=check_busybox2->readAll();
delete check_busybox2;if (command.contains("No such file or directory")) QMessageBox::information( this,"","Busybox uninstalled " + command); else QMessageBox::critical( this,"","Busybox not uninstalled! " + command);
@
I can run the command from the console and get expected output, capture the output to a file, etc. Why is readAll() returning an empty string?
-
Chances are that either:
the command you are giving QProcess, cstring) is not correct; or
the environment in which you "run the command from the console and get expected output" and the one that QProcess is working with are not the same.
In either case, you should check QProcess::error() and QProcess::exitStatus() for clues.
My money is on option 1: it looks like you are pasting the address and port number together without intervening whitepsace/punctuation. You should consider the other QProcess::start() overload.
BTW: There seems to be no reason to allocate the QProcess object on the heap.
-
You have a sharp eye, thanks:)
BTW: There seems to be no reason to allocate the QProcess object on the heap.
So, like this?
@
QProcess check_dir;
check_dir.setProcessChannelMode(QProcess::MergedChannels);
cstring = adb + " -s " + daddr + port + " shell ls /system/xbin/which";
check_dir.start(cstring);
check_dir.waitForFinished(-1);
command=check_dir.readAll();
@If I did it correctly above, why is this method better?
-
Hi,
AFAIK, when calling start and having arguments, you should use the same pattern as described "here":http://qt-project.org/doc/qt-5/qprocess.html#details
Passing parameters can be tricky -
Indeed, but in the present case, it's not useful to allocate QProcess on the heap to delete it right after since it won't survive the function.