#include <QCoreApplication>#include <QProcess>#include <QDebug>int main( int argc, char *argv[] ){ QCoreApplication app( argc, argv ); QProcess process; process.start("/bin/bash"); process.waitForStarted(); process.write("sbcl\n"); process.waitForReadyRead(); qDebug() << process.readAll(); process.write("(+ 3 2)\n"); process.waitForReadyRead(); qDebug() << process.readAll(); process.write("exit\n"); process.waitForFinished(); return 0;}
#include <QCoreApplication>#include <QProcess>#include <QDebug>int main( int argc, char *argv[] ){ QCoreApplication app( argc, argv ); QProcess process; process.start("sbcl\n"); process.waitForStarted(); process.write("(+ 3 2)\n"); process.waitForReadyRead(); qDebug() << process.readAll(); process.write("exit\n"); process.waitForFinished(); return 0;}
C++ (Qt)#include <QCoreApplication>#include <QProcess>#include <QDebug> int main( int argc, char *argv[] ){ QCoreApplication app( argc, argv ); QProcess process; process.start( "sbcl --script test.cl" ); process.waitForFinished(); qDebug() << process.readAll(); return 0;}
Lisp(PRINT( + 2 3 ))
Starting /home/grimmxxx/build-Primer-Desktop-Debug/Primer..."" /home/grimmxxx/build-Primer-Desktop-Debug/Primer exited with code 0
[b]myprocess.cpp[/b]#include "myprocess.h"myProcess::myProcess(QWidget *parent) : QDialog(parent){ sb.setText("Start SBCL"); ib.setText("Input Command"); lb.setText("(+ 3 2)"); QVBoxLayout *vl=new QVBoxLayout; vl->addWidget(&sb); vl->addWidget(&te); vl->addWidget(&le); vl->addWidget(&ib); vl->addWidget(&lb); setLayout(vl); connect(&sb,SIGNAL(clicked()),this,SLOT(startProcess())); connect(&ib,SIGNAL(clicked()),this,SLOT(doInput())); connect(&lb,SIGNAL(clicked()),this,SLOT(mathstart())); connect(&myProc,SIGNAL(readyReadStandardOutput()),this,SLOT(showOutput())); connect(&myProc,SIGNAL(readyReadStandardError()),this,SLOT(showOutput()));}void myProcess::startProcess(){ QString prog="sbcl"; 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()));}void myProcess::mathstart(){ QString h="(+ 3 2)\n"; myProc.write(h.toAscii());}int main(int argc, char *argv[]){ QApplication a(argc, argv); myProcess p; p.show(); return a.exec();}
[b]myprocess.h[/b]#include <QtGui>class myProcess : public QDialog{ Q_OBJECTpublic: myProcess(QWidget *parent=0);private slots: void startProcess(); void showOutput(); void doInput(); void mathstart();private: QProcess myProc; QTextEdit te; QLineEdit le; QPushButton sb,ib,lb;};