#include <stdio.h> void main(){ char s[128]; puts("begin test"); do { gets(s); puts(s); } while(s[0]); puts("end test");}
#include "myprocess.h"myProcess::myProcess(QWidget *parent) : QDialog(parent){ sb.setText("start"); ib.setText("input"); QVBoxLayout *vl=new QVBoxLayout; vl->addWidget(&sb); vl->addWidget(&te); vl->addWidget(&le); vl->addWidget(&ib); setLayout(vl); connect(&sb,SIGNAL(clicked()),this,SLOT(startProcess())); connect(&ib,SIGNAL(clicked()),this,SLOT(doInput())); connect(&myProc,SIGNAL(readyReadStandardOutput()),this,SLOT(showOutput())); connect(&myProc,SIGNAL(readyReadStandardError()),this,SLOT(showOutput()));}void myProcess::startProcess(){ QString prog="testcon.exe"; myProc.start(prog); if(myProc.waitForStarted()) te.append(QString("Program <b>%1</b> started").arg(prog)); else te.append(QString("Can't start program <b>%1</b>").arg(prog));}void myProcess::doInput(){ QString s=le.text()+"\n"; if(myProc.write(s.toAscii())!=-1) le.clear();}void myProcess::showOutput(){ te.append(QString::fromLocal8Bit(myProc.readAllStandardOutput())); te.append(QString::fromLocal8Bit(myProc.readAllStandardError()));}int main(int argc, char *argv[]){ QApplication a(argc, argv); myProcess p; p.show(); return a.exec();}
#include <QtGui>class myProcess : public QDialog{ Q_OBJECTpublic: myProcess(QWidget *parent=0);private slots: void startProcess(); void showOutput(); void doInput();private: QProcess myProc; QTextEdit te; QLineEdit le; QPushButton sb,ib;};
setvbuf(stdout,NULL,0,_IOFBF);
keeping standard output and standard error data in separate internal buffers
psql -l -U postgres
C++ (Qt)void readyReadStandardError () иvoid readyReadStandardOutput ()