PDA

View Full Version : Shell script crash launched by QProcess, works launched manually



Mansurji
17th April 2014, 15:16
Hi,

I'm on intership for a research lab, my duty is to provide a GUI for a good algorithm that until now needs to be launched and parametered console-style. I need to launch a heavy-processing shell script through GUI.

I use QtCreator 2.8.1 based on Qt 5.1.1, along with MinGW 4.8 and MSYS 1.0.17.

Yet I'm trying to launch the script through a QProcess with this syntax :

MainWindow.cpp


void MainWindow::on_pushButton_clicked() {

process = new QProcess(this);
process->setProcessChannelMode(QProcess::MergedChannels);
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(displayLog()));

QString command = "sh ./myscript.sh";
process->start(command);

}


With process declared as a QProcess*, displayLog() appending the output to a QPlainTextEdit and $PATH knowing MSYS/bin

The script runs, the log displays but in the stderr output it shows that at one point there's a memory allocation problem within one of the scripts crashing most of its functionnalities.

The nasty thing is that when I open cmd.exe and execute manually "sh ./myscript.sh", this allocation problem doesn't appear. I've tried to launch process->start("cmd /K start sh ./myscript.sh"), result is the same. Also with startDetached, everytime the script is launched through Qt it crashes.

My question is : is there a memory limitation for a QProcess on the heap ? Is there a way to extend the memory allocated to a QProcess ? What in the QProcess architecture could prevent a sh command to work the same as launched manually ? I've read the QProcess official doc aswell as many forum threads but couldn't find any hints, it's turning me crazy.

Thanks for your answers ! And overall thanks to the community, this forum is really useful on a daily-basis.

Edit: myscript.sh is a launcher that execute a bunch of others .sh, which end executing a fortran core algorithm.

Edit: the error message about a bad allocation is internally wrote in a script. It says : Allocation error var1->var2 in function COM_init.c, 805 306 368 bytes needed

Mansurji
18th April 2014, 10:02
I've just tried to replace the QProcess by this:



QString command = "sh ./myscript.sh";
system(qPrintable(command));


Error is the same. As anyone any idea ?

anda_skoa
18th April 2014, 11:00
I doubt this is related to Qt and your attempt with system() seems to confirm that.

Maybe there is some system setting that limits the amount of memory a process group can allocate or that somehow restricts child processes.

Might be helpful to check on a Windows forum.

Cheers,
_

Mansurji
18th April 2014, 15:27
Thanks for your input anda. Indeed it could come from the way Windows handle a process generated through Qt, I will dig it.

Btw I've tried to use QThread instead of QProcess, same error. Does someone know another way to launch a DOS command, other than a QProcess, a QThread or a direct system() call ?

Mansurji
22nd April 2014, 16:34
Problem solved.

Easy solution: I had to launch the .exe generated instead of launching it through the IDE. Qt wasn't able to allocate 1,6 Go by itself.

Thanks for your help!

Also, to answer my previous question : you can launch a command to cmd.exe using QProcess, QThread, system(), CreateProcess, ShellExecute