PDA

View Full Version : Command run in terminal but not in QProcess while PATHs are inserted



abbaasi69
25th July 2020, 23:18
Stackoverflow question (https://stackoverflow.com/questions/63089848/command-run-in-terminal-but-not-in-qprocess-while-paths-are-inserted)
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:



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.

d_stranz
26th July 2020, 00:08
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.

abbaasi69
26th July 2020, 18:47
Thanks but as I mentioned in the post, I'm using Ubuntu not Windows.

d_stranz
27th July 2020, 21:40
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?

abbaasi69
12th August 2020, 18:58
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?

d_stranz
12th August 2020, 23:54
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.

Ginsengelf
13th August 2020, 07:32
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