What SIGNAL to monitor for incorrect QProocess ?
-
I am passing char * to QProcess.
As far as I can tell; QProcess has no option for passing char*, but the QProcess starts and finishes ... but does not deliver expected results.Which one of QProcess standard SIGNALs should I monitor for possible error?
void errorOccurred(QProcess::ProcessError error) void finished(int exitCode, QProcess::ExitStatus exitStatus = NormalExit) void readyReadStandardError() void readyReadStandardOutput() void started() void stateChanged(QProcess::ProcessState newState)
And per my other post - how do I make the passed (error) data humanly readable - since I do no define them.
PS
If I do pass QSTring to QPProcess - what is the corrent systex for passinf "system" function ?
I did try splitting to "system" and then arguments - but it does not work with the "system" (function) that way .YES, I can go back to passing data to "bash"...
BUT bash script does not accept some standard options likes "|" and "tee".const char *command = "hcitool -i hci0 scan --flush | tee /tmp/temp"; //command = "hcitool -i hci0 scan --flush | tee /tmp/temp "; //command = "hcitool | tee /tmp/temp "; //ystem(command); // or even just //system("rfkill list > textEdit"); // exit(66); //QString s = "hcitool -i hci0 scan --flush | tee /tmp/temp" process ->start(command); // system("hcitool -i hci0 scan --flush >>/tmp/temp ")); process->state();
-
I am passing char * to QProcess.
As far as I can tell; QProcess has no option for passing char*, but the QProcess starts and finishes ... but does not deliver expected results.Which one of QProcess standard SIGNALs should I monitor for possible error?
void errorOccurred(QProcess::ProcessError error) void finished(int exitCode, QProcess::ExitStatus exitStatus = NormalExit) void readyReadStandardError() void readyReadStandardOutput() void started() void stateChanged(QProcess::ProcessState newState)
And per my other post - how do I make the passed (error) data humanly readable - since I do no define them.
PS
If I do pass QSTring to QPProcess - what is the corrent systex for passinf "system" function ?
I did try splitting to "system" and then arguments - but it does not work with the "system" (function) that way .YES, I can go back to passing data to "bash"...
BUT bash script does not accept some standard options likes "|" and "tee".const char *command = "hcitool -i hci0 scan --flush | tee /tmp/temp"; //command = "hcitool -i hci0 scan --flush | tee /tmp/temp "; //command = "hcitool | tee /tmp/temp "; //ystem(command); // or even just //system("rfkill list > textEdit"); // exit(66); //QString s = "hcitool -i hci0 scan --flush | tee /tmp/temp" process ->start(command); // system("hcitool -i hci0 scan --flush >>/tmp/temp ")); process->state();
@AnneRanch
You have asked this so many times, and been answered. You cannot executehcitool -i hci0 scan --flush | tee /tmp/temp
as thecommand
inprocess ->start(command)
. The answer is always the same:process ->start("/bin/sh", QStringList() << "-c" << command);
YES, I can go back to passing data to "bash"...
BUT bash script does not accept some standard options likes "|" and "tee".
Completely incorrect. It is only either
/bin/sh
or/bin/bash
which does accept and interpret|
.tee
has nothing to do with the shell, and works fine from either.If I do pass QSTring to QPProcess - what is the corrent systex for passinf "system" function ?
There is no
system
-anything to pass toQProcess
.system()
is an alternative to usingQProcess
. You are better usingQProcess
in Qt programs and notsystem()
. There is nothingsystem()
does thatQProcess()
cannot do, but there are things you can do withQProcess
which cannot be done withsystem()
. You could save yourself time but not trying to usesystem()
, I have shown you the equivalentprocess ->start()
to use instead.Which one of QProcess standard SIGNALs should I monitor for possible error?
void errorOccurred(QProcess::ProcessError error)
errorOccurred()
is the signal for errors launchingQProcess
. You will doubtless be interested in other things which happen that are not process errors, even if you might think they should be. They may be reported by reading stderr (readyReadStandardError()
) and possibly stdout too.For the simplest case just use
const char *command = "hcitool -i hci0 scan --flush | tee /tmp/temp"; process ->start("/bin/sh", QStringList() << "-c" << command); process->waitForFinished(); qDebug() << process->readAllStandardError(); qDebug() << process->readAllStandardOutput();
You should also
connect
on theerrorOccurred
signal, just in case.