Results 1 to 7 of 7

Thread: Command run in terminal but not in QProcess while PATHs are inserted

  1. #1
    Join Date
    Jul 2020
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Angry Command run in terminal but not in QProcess while PATHs are inserted

    Stackoverflow question
    I want to run a command in Ubuntu via Qt using QProcess. My command is fluent3DMeshToFoam <mesh address> and when I run it into terminal its OK and produces sum output and files in a specific location. But I have problem with running it using QProcess.

    I have noticed that I should add the path of fluent3DMeshToFoam to ProcessEnvironment of my QProcess object. So I did:

    Qt Code:
    1. QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    2. env.insert("PATH" , env.value("PATH") + ":"+"<path of fluent3DMeshToFoam>");
    3. myProcess.setProcessEnvironment(env);
    4. myProcess.start("fluent3DMeshToFoam" , QStringList() << "<mesh address>");
    5. myProcess.waitForFinished(-1);
    To copy to clipboard, switch view to plain text mode 
    I connected readyRead()and errorOccurred() signals and after I run, the errorOccurred signal emits and the following error shows:

    execve: No such file or directory

    I searched alot and could not find out where the problem is. thanks.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,689
    Thanks
    257
    Thanked 750 Times in 740 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Command run in terminal but not in QProcess while PATHs are inserted

    If this is Windows, PATH strings are separated by semicolon (';') not colon (':'). Also, if this is Windows, be sure your <path of fluent3dMeshToFoam> is properly escaping backslashes: "C:\\Path\\To\\MeshToFoam". Likewise, be sure that <mesh address> is also escaped if you have an absolute path to the file or if you are specifying just the file name, be sure QProcess thinks that your working directory is the same place you have the file.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2020
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Command run in terminal but not in QProcess while PATHs are inserted

    Thanks but as I mentioned in the post, I'm using Ubuntu not Windows.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,689
    Thanks
    257
    Thanked 750 Times in 740 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Command run in terminal but not in QProcess while PATHs are inserted

    Oops, missed that. Is QProcess running as the same user and group as your terminal window? Are you sure the working directory for QProcess is the same as the location of your mesh file? Have you tried running a different executable, maybe one that doesn't need an input argument?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jul 2020
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Command run in terminal but not in QProcess while PATHs are inserted

    Yes, I actually tried setting the working directory in the location of running file. As I mentioned, the command "fluent3DMeshToFoam" works well in terminal (even if the terminal did not opened in location of mesh)
    I realized that the "fluent3DMeshToFoam" is an ELF file. Could it be the reason for not running?

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,689
    Thanks
    257
    Thanked 750 Times in 740 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Command run in terminal but not in QProcess while PATHs are inserted

    I realized that the "fluent3DMeshToFoam" is an ELF file. Could it be the reason for not running?
    I wouldn't think so. It is the standard format for executable files for most linux platforms. You could run a test by substituting a non-ELF program to see if that executes correctly.

    Or something else to try: Use bash as the process and add fluent3DMeshToFoam as the first item in your argument list.
    Last edited by d_stranz; 13th August 2020 at 00:59.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    451
    Thanks
    9
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Command run in terminal but not in QProcess while PATHs are inserted

    Hi, have you tried to use the complete path for fluent3DMeshToFoam as the argument for QProcess, instead of editing the PATH variable?
    So for line 4 something like:
    myProcess.start("/usr/local/bin/fluent3DMeshToFoam" , QStringList() << "<mesh address>");
    or whatever the absolute path is.

    Ginsengelf

Similar Threads

  1. Sending command to terminal
    By dcasey627 in forum Newbie
    Replies: 3
    Last Post: 4th April 2016, 09:27
  2. Execute command without terminal window
    By RolandHughes in forum Qt Programming
    Replies: 2
    Last Post: 17th June 2015, 10:38
  3. Replies: 3
    Last Post: 23rd February 2011, 09:50
  4. Replies: 7
    Last Post: 15th April 2007, 02:39
  5. call bash/terminal command with QT
    By myta212 in forum Newbie
    Replies: 1
    Last Post: 13th November 2006, 16: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.