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:
Code:
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("PATH" , env.value("PATH") + ":"+"<path of fluent3DMeshToFoam>");
myProcess.setProcessEnvironment(env);
myProcess.
start("fluent3DMeshToFoam" ,
QStringList() <<
"<mesh address>");
myProcess.waitForFinished(-1);
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.
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.
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.
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?
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?
Re: Command run in terminal but not in QProcess while PATHs are inserted
Quote:
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.
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