Results 1 to 5 of 5

Thread: Shell script crash launched by QProcess, works launched manually

  1. #1
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Shell script crash launched by QProcess, works launched manually

    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
    Qt Code:
    1. void MainWindow::on_pushButton_clicked() {
    2.  
    3. process = new QProcess(this);
    4. process->setProcessChannelMode(QProcess::MergedChannels);
    5. connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(displayLog()));
    6.  
    7. QString command = "sh ./myscript.sh";
    8. process->start(command);
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by Mansurji; 17th April 2014 at 16:24.

  2. #2
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Shell script crash launched by QProcess, works launched manually

    I've just tried to replace the QProcess by this:

    Qt Code:
    1. QString command = "sh ./myscript.sh";
    2. system(qPrintable(command));
    To copy to clipboard, switch view to plain text mode 

    Error is the same. As anyone any idea ?

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Shell script crash launched by QProcess, works launched manually

    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,
    _

  4. #4
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Shell script crash launched by QProcess, works launched manually

    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 ?

  5. #5
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Shell script crash launched by QProcess, works launched manually

    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

Similar Threads

  1. Replies: 11
    Last Post: 5th July 2011, 12:11
  2. Replies: 5
    Last Post: 10th January 2011, 01:19
  3. QProcess: how to run shell script with password?
    By cutie.monkey in forum Qt Programming
    Replies: 0
    Last Post: 23rd March 2010, 06:43
  4. Driver loaded only when launched from Creator
    By vieraci in forum Qt Tools
    Replies: 0
    Last Post: 16th September 2009, 03:56
  5. Qt Public Repository Launched!
    By lpotter in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2009, 01:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.