Using bash with QProcess
-
wrote on 11 Jul 2011, 14:02 last edited by
Does anyone used QProcess to run bash?
How can i exit the bash process?
I tries bashProcess->write("exit\n\r") but it does'nt seems to work -
wrote on 11 Jul 2011, 14:15 last edited by
hi aabc ,
I found this in the QProcess Class Reference :
@
The finished() signal provides the exit code and exit status of the process as arguments, and you can also call exitCode() to obtain the exit code of the last process that finished, and exitStatus() to obtain its exit status. If an error occurs at any point in time, QProcess will emit the error() signal. You can also call error() to find the type of error that occurred last, and state() to find the current process state.@ -
wrote on 11 Jul 2011, 14:18 last edited by
I explain it again
My code is:
@
QProcess* process = new QProcess();
process->start("bash");
process->waitForStarted();
process->write("route > /home/abc/aaa.txt\n\r");
process->write("exit\n\r");
process->waitForFinished();
@For some reason - the process does not end after the "process->write("exit\n\r");" and the last line does not get called ?
Any ideas? -
wrote on 11 Jul 2011, 14:41 last edited by
Try removing the '\r' at the end of your lines, only '\n' is needed on linux/unix.
And with that particular code, you could avoid using an intermediate file, by getting the output directly from QProcess:
@QProcess* process = new QProcess();
process->start("route");
process->waitForFinished();
QString output = process->readAll();@ -
wrote on 11 Jul 2011, 14:41 last edited by
Thanks!!!
1/5