I'm quite new to MacOS and I'm trying to build my program on Mac OS for the first time. So far Windows and Linux were my target platforms. Everything works fine and I'm again impressed on the degree of platform independence that Qt offers.
But there is one problem:
I have a program (assume it's called foo) that attempts to call external tools (latex, gs) via QProcess. It should be quite straight forward and works fine on Windows and Linux
process.start("latex ......");
bool success = process.waitForStarted();
if(!success)
{
int error = process.error();
qDebug("waitForStarted: error=%d\n", error);
....
}
QProcess process;
process.start("latex ......");
bool success = process.waitForStarted();
if(!success)
{
int error = process.error();
qDebug("waitForStarted: error=%d\n", error);
....
}
To copy to clipboard, switch view to plain text mode
On Mac OS that simply doesn't work when I launched my application (foo) via the bundle file (foo.app). process.start() returns false and the error code is 0. But it works fine when I start foo via the executable that is inside the bundle under foo.app/Contents/MacOS/foo
I notice that in that case a shell window pops up. Perhaps now it is executed in a different execution environment. Now foo can call all external tools.
Assuming it is perhaps the PATH variable from the environment, I tried to add the required path entries to the process environment with
QProcessEnvironment sysenv = QProcessEnvironment::systemEnvironment();
QString path
= sysenv.
value("PATH");
if(path != "")
path += ":";
path += "/usr/texbin:/usr/local/bin";
sysenv.remove("PATH");
sysenv.insert("PATH", path);
process.setProcessEnvironment(sysenv);
QProcessEnvironment sysenv = QProcessEnvironment::systemEnvironment();
QString path = sysenv.value("PATH");
if(path != "")
path += ":";
path += "/usr/texbin:/usr/local/bin";
sysenv.remove("PATH");
sysenv.insert("PATH", path);
process.setProcessEnvironment(sysenv);
To copy to clipboard, switch view to plain text mode
It still doesn't work. Even if it would, I would prefer not messing around with PATH values. How can I get the same execution execution environment as in the shell? Do I have to wrap my call inside a script and execute that via "sh"?
Why is a program started in a different context depending on whether the bundle or the exe from within the bundle is run?
Google didn't really help on that.
Bookmarks