Results 1 to 6 of 6

Thread: Errors: run command with system call in a qt application

  1. #1
    Join Date
    Jul 2015
    Posts
    26
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Errors: run command with system call in a qt application

    I installed a MPI program in /opt/mpi. In my Qt code, I use system( "mpiexec -machinefile host -n 1 app.exe") call to run the command, the code complains mpiexec can not be found
    Although /opt/mpi/bin is in the path. There is no issue when I run the command manually. To solve this problem, I have to add the absolute path in front of mpiexec, like
    system( "/opt/mpi/bin/mpiexec -machinefile host -n 1 app.exe").

    I wrote a small C++ code to test the command above

    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
    system( "mpiexec -machinefile host -n 1 app.exe" );
    return 0;
    }

    the command runs successfully. It looks like system call inside Qt does not recognize the settings in Path.

    Another problem is that app.exe uses a library abc.so in /opt/app/lib. When I run /opt/mpi/bin/mpiexec -machinefile host -n 1 app.exe, the code complains about abc.so can not be found.
    However, from a pure C++ code or command line, no problem at all because I set abc.so path in LD_LIBRARY_PATH. It must be a Qt problem.

    system call inside Qt ignores lib path too.

    What is the root reason? Thanks for your help in advance.

  2. #2
    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: Errors: run command with system call in a qt application

    Are you sure that you run the Qt program in an enviroment that has these variables set they way you think they are?

    What does
    Qt Code:
    1. qDebug() << qgetenv("PATH") << qgetenv("LD_LIBRARY_PATH");
    To copy to clipboard, switch view to plain text mode 
    say?

    Btw, a nicer way to run an external program in Qt, especially if the Qt program has a UI (and therefore should not block), is to use QProcess.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2015
    Posts
    26
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Errors: run command with system call in a qt application

    Thank you for your reply. There is no output for the settings in the bash file. It is obvious that settings of PATH and LD_LIBRARY_PATH in bash file are ignored.
    I tried with system( "bash -c 'mpiexec -machinefile host -n 1 app.exe'" ); No help.
    Even when I copy abc.so to the same folder of app.exe, the error is still there. Right, current dir :.: is not included in the PATH too.
    I will try QPorcess.
    Last edited by newcfd; 17th September 2015 at 18:13.

  4. #4
    Join Date
    Jul 2015
    Posts
    26
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Errors: run command with system call in a qt application

    qDebug() << qgetenv("PATH") << qgetenv("LD_LIBRARY_PATH");
    Library path is empty. Is there a way to set LD_LIBRARY_PATH inside a Qt application?

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Errors: run command with system call in a qt application

    Maybe you want to look at QProcessEnvironment. Note that you cannot change the current environment this way, but you can change the environment you pass to a QProcess instance.

  6. #6
    Join Date
    Jul 2015
    Posts
    26
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Errors: run command with system call in a qt application

    good to know. Thanks.

Similar Threads

  1. Need to Execute an system command, in QT
    By gunturrohith in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 27th November 2014, 08:28
  2. Replies: 4
    Last Post: 14th July 2009, 03:27
  3. System Command QProcess
    By jd in forum Qt Programming
    Replies: 7
    Last Post: 10th February 2009, 17:36
  4. command system
    By peace_comp in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2008, 00:22
  5. call bash/terminal command with QT
    By myta212 in forum Newbie
    Replies: 1
    Last Post: 13th November 2006, 15:38

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.