#include <QtCore/QCoreApplication>#include "QProcess"#include <iostream>int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QProcess test; QStringList arglist; arglist<<"2"<<"100"<<"4"; test.start("D:\qtprocessTest\Release\qtprocessTest", arglist); test.setReadChannel(QProcess::StandardOutput); char *data; std::cout<<test.bytesAvailable()<<"\t"<<test.bytesToWrite()<<"\t"; test.read(data,100500); std::cout<<data; return a.exec();}
#include <iostream>int main(int argc,char* argv[]){ std::cout<<"program name:"<<argv[0]<<"/n number of arguments: "<<argc<<"/n"; for(int i=1;i<argc;i++) std::cout<<argv[i]<<"/t"; int input; std::cin>>input; std::cout<<1<<"/n"; //system("pause"); return 777;}
char *data; test.read(data,100500);
#include <QtCore/QCoreApplication>#include "QProcess"#include <iostream>int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QProcess test; QStringList arglist; arglist<<"2"<<"100"<<"4"; test.start("D:\qtprocessTest\Release\qtprocessTest", arglist); test.setReadChannel(QProcess::StandardOutput); test.waitForStart(); test.waitForFinished(); char *data= char[30]; std::cout<<test.bytesAvailable()<<"\t"<<test.bytesToWrite()<<"\t"; test.read(data,30); std::cout<<data; return a.exec();}
C++ (Qt)char *data= char[30];
C++ (Qt) test.start("D:\\qtprocessTest\\Release\\qtprocessTest", arglist);
...test.waitForStart(); test.write("666"); test.waitForFinished();...
...char *PutinsNumber= new char[5];cin>>PutinsNumber;..
#include <QtCore/QCoreApplication>#include "testing.h"int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); testing test; test.run(); return a.exec();}
#ifndef TESTING_H#define TESTING_H#include <QProcess>#include <QObject>#include <iostream>using namespace std;class testing:public QObject{ Q_OBJECTpublic: testing(); QProcess process; void run();public slots: void dataOnStdout(); void errorOccured(QProcess::ProcessError errorId); void finishReading(); void bytesWritten(qint64 num); void processClosing();};#endif // TESTING_H
#include "testing.h"testing::testing(): QObject(0){ connect(&process,SIGNAL(readyReadStandardOutput()),this,SLOT(dataOnStdout())); connect(&process,SIGNAL(error(QProcess::ProcessError)),this,SLOT(errorOccured(QProcess::ProcessError))); connect(&process,SIGNAL(readChannelFinished()),this,SLOT(finishReading())); connect(&process,SIGNAL(bytesWritten(qint64)),this,SLOT(bytesWritten(qint64))); connect(&process,SIGNAL(aboutToClose()),this,SLOT(processClosing()));}void testing::run(){ process.start(QString("C:\\Qt\\prj\\testing\\certainprocess 1 2 3 4 5 6 7 8 9 0")); cout<<"\n > [qt]process.start();"; process.write("meow",60); process.write("gaf-gaf",60); process.write("end",60); if(!process.waitForStarted(15000))cout<<"[qt]"<<process.error(); else cout<<"\n > [qt]process.waitForStarted(); "; if(!process.waitForFinished(15000))cout<<"[qt]"<<process.error(); else cout<<"\n > [qt]process.waitForFinish(); "; process.kill();}void testing::dataOnStdout(){ cout<<"\n >dataOnStdout"; QByteArray str=process.readAllStandardOutput(); cout<<"\n stdout>"<<str.data();}void testing::errorOccured(QProcess::ProcessError errorId){ cout<<"\n >errorOccured"; cout<<"\n >error :" <<errorId;}void testing::finishReading(){ cout<<"\n > reading from process finished";}void testing::bytesWritten(qint64 num){ cout <<"\n > "<<num<<" bytes written";}void testing::processClosing(){ cout<<"\n > process is closing";}
#include <iostream>#include "stdio.h"#include "string.h"using namespace std;int main(int argc, char* argv[]){ cout<<"[process itself]program name: "<<argv[0]<<endl; for(int i=1;i<argc;i++) cout<<"[process itself]parametrs: "<<argv[i]<<", "; cout<<endl; char *str=new char[60]; cin>>str; cout<<"[process itself]----->"<<str<<endl; delete []str; cout << "[process itself]\n bye bye !" << endl; return 0;}
cin>>str;
#include <iostream>#include "stdio.h"#include "string.h"using namespace std;int main(int argc, char* argv[]){ cout<<"[process itself]program name: "<<argv[0]<<endl; for(int i=1;i<argc;i++) cout<<"[process itself]parametrs: "<<argv[i]<<", "; cout<<endl; char *str=new char[60]; cout << "[process itself]\n first value " << endl; cin>>str; cout<<"[process itself]----->"<<str<<endl; cout << "[process itself]\n second value " << endl; cin>>str; cout<<"[process itself]----->"<<str<<endl; cout << "[process itself]\n third value " << endl; cin>>str; cout<<"[process itself]----->"<<str<<endl; delete []str; cout << "[process itself]\n bye bye !" << endl; return 0;}
C++ (Qt) process.write("meow\n"); process.write("gaf-gaf\n"); process.write("end\n");