[SOLVED] QProcess launching CMD and compiling with it (Windows 8)
-
Hello
I need my project to compile stuff. So I created a QProcess and started CMD(output is redirected to textEdit)... Now if I then write to it "dir \n" it works great... Everything is displayed as it should(exactly the same way as in a real console)... but if instead of writing "dir \n" I write "g++ (parameters, files...)" All I get in the textEdit is the command "g++ (parameters, files...)" but no other output... I don't know why... Any help is appreciated... Thanks :Dcode:
@void MainWindow::compileProject(mbedProject *proj,QString *pars){
QString completePars=*pars+" "+proj->file->fileName()+"\n\r";compilerProcess->start("cmd"); if(!compilerProcess->waitForStarted()){ qDebug("Error starting cmd!"); }else{ compilerProcess->waitForReadyRead(100); compilerProcess->waitForFinished(100); //compilerProcess->write(("\""+compilerLocation+"/arm-none-eabi-g++.exe\" "+completePars).toUtf8().constData()); compilerProcess->write("dir \n"); compilerProcess->closeWriteChannel(); compilerProcess->waitForBytesWritten(100); compilerProcess->waitForReadyRead(100); compilerProcess->waitForFinished(100); if(compilerProcess->exitCode()==0){ qDebug("Compilation Successful!"); }else{ qDebug("Compilation Failed!"); // compilation failed } }
}@
Picture when writing dir \n
https://drive.google.com/file/d/0B0bKAstz-Jy6OEVXT3I4VXhKQVk/edit?usp=sharing
Picture when writing g++...
https://drive.google.com/file/d/0B0bKAstz-Jy6ZXhPZ0d1TWtTV2M/edit?usp=sharingAnd if I enter the exact same g++... to a CMD opened at that exact location(also with the ""(because of spaces in the path)) I get output... I know that I can't compile .h files it is just what I had at hand...
And I am redirecting both stdout and stderr(or at least I think so)...
@connect(compilerProcess,SIGNAL(readyRead()),this,SLOT(updateCompilerOutput()));@@void MainWindow::updateCompilerOutput(){
compilerTextEdit->insertPlainText(compilerProcess->readAll());
compilerTextEdit->verticalScrollBar()->setValue(compilerTextEdit->verticalScrollBar()->maximum());
}@So what is the difference that causes that dir is ok and g++ is not?
-
Hi maybe a stupid question but haven't you forgotten the \n, I mean instead try:
@compilerProcess->waitForFinished(100);
compilerProcess->write(("""+compilerLocation+"/arm-none-eabi-g++.exe""+completePars + "\n").toUtf8().constData());
@ -
I saw your compiler string. It is too big and difficult to experiment. Did you check the command on command line. Copy-paste the same command which is in image you pasted and see it runs. If you are able to run that, you should not have problem here as well
-
[quote author="hskoglund" date="1404339237"]Hi maybe a stupid question but haven't you forgotten the \n, I mean instead try:
@compilerProcess->waitForFinished(100);
compilerProcess->write(("""+compilerLocation+"/arm-none-eabi-g++.exe""+completePars + "\n").toUtf8().constData());
@ [/quote]I have \n\r in completePars
@QString completePars=*pars+" "+proj->file->fileName()+"\n\r";@ -
[quote author="Dheerendra" date="1404358676"]Copy-paste the same command which is in image you pasted and see it runs. If you are able to run that, you should not have problem here as well[/quote]
https://drive.google.com/file/d/0B0bKAstz-Jy6eTVIQkZNcEVKU2c/edit?usp=sharing
I copy-pasted it and it did output something...(now its a different file) Could it be possibly because of the missing \n? maybe even if I put it to the string but after the conversion to const char* it disappears or something...?
-
And if I enter unknown command ("blahblahblah \n") in CMD I get "blahblahblah is unrecognized...blahblahblah"... and in my app I get nothing... well... I get a new line to enter new command(like if the command executed with no output)
-
And another thing is that if I run this code:
@QString completePars=proj->file->fileName();
connect(compilerProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(updateCompilerOutput()));
connect(compilerProcess,SIGNAL(readyReadStandardError()),this,SLOT(updateCompilerOutput()));
compilerProcess->execute(compilerLocation+"/arm-none-eabi-g++.exe",QStringList(completePars));@the output comes out in the Application output in Qt Creator but it does not come out in the app... and the slot updateCompilerOutput never gets called...why?
-
Now its fixed... all I needed was this line of code...
@compilerProcess->setProcessChannelMode(QProcess::MergedChannels);@
But thanks for your time :D