Re: Problem with qprocess
How do you read data from QProcess?
Re: Problem with qprocess
I have tried these ones:
Code:
m_process->setCommunication( Q3Process::Stdin | Q3Process::Stdout | Q3Process::Stderr | Q3Process::DupStderr);
m_process->start()
while(m_process->canReadLineStdout() )
qDebug()<<m_process->readLineStdout();
Code:
connect( m_process, SIGNAL(readyReadStdout()), this, SLOT(readStandardOutput()) )
m_process->setCommunication( Q3Process::Stdin | Q3Process::Stdout | Q3Process::Stderr | Q3Process::DupStderr);
m_process->start();
....
qDebug()<<m_process-> readStdout() [in readStandardOutput() slot]
Code:
m_process
->setProcessChannelMode
(QProcess::MergedChannels);
connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStandardError()));
connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandardOutput()));
startProcess(m_progname);
...
qDebug()<<
QString(m_process
->readAllStandardError
());
[readStandardError
() slot] ...
qDebug()<<
QString(m_process
->readAllStandardOutput
());
[readStandardOutput
() slot] ...
[as I said if I close write channel in readStandardError() slot, I will get those lines ]
I even tried to redirect outputs to files, but again no success in getting those lines before stdin prompt. Am I doing something wrong?
I have reviewed some codes of others (both qt3 and qt4) especially codes of IDEs but no success. I would be happy even if you point me some where (code, thread..) to learn more.
I tried Google and Koders, but no success again.
Besides, is there any non-qt work-around for this problem? Do you know some pure C++ console like code, which is wrapped in qt?
Re: Problem with qprocess
Quote:
Originally Posted by
resal
m_process->setProcessChannelMode(QProcess::MergedChannels) ;
Shouldn't you use QProcess::SeparateChannels here (i.e. the default mode)?
What do the "out" and "err" files contain after you do the following?
Quote:
$ echo "3" > in # or whatever command is for "do nothing and exit"
$ thatcmd < in > out 2> err
Re: Problem with qprocess
Quote:
Originally Posted by
jacek
Shouldn't you use QProcess::SeparateChannels here (i.e. the default mode)?
I tried separate channels first, but to make stdout unbuffered, I used merged channel too. no success in both.
Quote:
Originally Posted by
jacek
What do the "out" and "err" files contain after you do the following?
what that they expected to have. stderr messages in err file, and stdout menu in out file.[ My fault: when I said no success in getting those lines in redirections, I meant that I couldn't have those lines BEFORE writing to stdin. The problem is to have menu then providing input based on this menu.]
Re: Problem with qprocess
Do you know any (not-very-complicated) (especially in Qt4) application with similar functionality? I mean an application which is a GUI that runs some commands AND communicates with those commands while they are still running(i.e. it doesn't wait for commands to finish and then gets the output; rather it gets the messages of commands during execution, displays the messages to user and then writes user options to command stdin). I reviewed konsole code, but got lost in (kde-related) classes....
thanks
Re: Problem with qprocess
Quote:
Originally Posted by
resal
what that they expected to have. stderr messages in err file, and stdout menu in out file.
OK, so at least that application isn't playing any tricks by detecting whether the input comes from a file or a terminal.
There is no way to control the buffers through QProcess, but maybe reimplementing QProcess::setupChildProcess() will help. You might try to alter the buffer size with setbuf, but I'm not sure if it's going to work (I think I've tried it to solve a similar problem, but without a success).
Quote:
Originally Posted by
resal
Do you know any (not-very-complicated) (especially in Qt4) application with similar functionality?
Unfortunately, I don't.
Quote:
Originally Posted by
resal
I reviewed konsole code, but got lost in (kde-related) classes....
kconsole doesn't use pure QProcess, but a K3Process subclass. The most important difference is that KDE allows you to use a pty device to communicate with the child process.
Here are the relevant sources:
http://websvn.kde.org/trunk/KDE/kdeb....h?view=markup
http://websvn.kde.org/trunk/KDE/kdeb...pp?view=markup
http://api.kde.org/4.0-api/kdelibs-a...rocess_8h.html
http://api.kde.org/4.0-api/kdelibs-a...classKPty.html
Re: Problem with qprocess
Thank you jacek.
Quote:
Originally Posted by
jacek
I have reviewed them before. As you said the trick in konsole is using kpty device.
Quote:
Originally Posted by
jacek
There is no way to control the buffers through QProcess, but maybe reimplementing
QProcess::setupChildProcess() will help. You might try to alter the buffer size with setbuf, but I'm not sure if it's going to work (I think I've tried it to solve a similar problem, but without a success).
I think this is the case. I 've played with setupChild Process() but I couldn't figured it out how to use it. I found these links though :
http://labs.trolltech.com/blogs/2006...with-qprocess/
http://www.koders.com/default.aspx?s...arch&la=*&li=*
http://www.koders.com/cpp/fidCB4E6B7...upchildprocess
The first one, I think, is the solution. I tried to find some example of its usage, so I search koders, which didn't help me a lot.
Can anyone write an example code about how to use the method that first link suggest?
Thanks in advance.
Re: Problem with qprocess
Quote:
Originally Posted by
resal
I think this is the case. I 've played with setupChild Process() but I couldn't figured it out how to use it.
You have to create a QProcess subclass and use that new class instead.
Code:
class UnbufferedProcess
: public QProcess{
protected:
void setupChildProcess()
{
::setbuf( stdout, 0 );
}
};
But as I said, I'm not sure if it's going to help.
Quote:
Originally Posted by
resal
The first one, I think, is the solution. I tried to find some example of its usage, so I search koders, which didn't help me a lot.
You use it just like QProcess, but I'm not sure if it solves your problem. I think that this class is useful if the process you want to start insists on reading from the terminal. Nevertheless, try it.