Qt-interest Archive, July 2007
QProcess and setEnvironment()
Message 1 in thread
Hi,
I'm trying to start an external program using QProcess() and am having
difficulties setting my PATH variable.
Here is my code:
QStringList env = process.environment();
env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive),
"PATH=\\1:/usr/local/bin");
So I know the string is being modified properly in the env string list
and I am adding it to the environment of process like so:
process.setEnvironment(env);
However, my program is still not being found.
Is there anything else I have to do, or do differently?
Thanks!
-Andrew
--
[ signature omitted ]
Message 2 in thread
On 27.07.07 11:57:24, Andrew Sutherland wrote:
> Hi,
>
> I'm trying to start an external program using QProcess() and am having
> difficulties setting my PATH variable.
>
> Here is my code:
>
> QStringList env = process.environment();
> env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive),
> "PATH=\\1:/usr/local/bin");
>
> So I know the string is being modified properly in the env string list and I am
> adding it to the environment of process like so:
>
> process.setEnvironment(env);
>
> However, my program is still not being found.
>
> Is there anything else I have to do, or do differently?
Well, that can't work unless you start your program with a shell around
it. The reason is simply that finding a program via PATH is done by the
shell, not by the functions that QProcess uses to execute a process.
So you'd need to do something like start("/usr/bin/sh","yourapp"),
however if another binary called yourapp is somewhere in PATH before
/usr/local/bin then that won't work as you expect either.
I strongly suggest to use the full path to the executable you want to
start, that will save you from a lot of subtle bugs later on (or users
complaining because that doesn't work due to changed PATH's on their
pc).
Andreas
--
[ signature omitted ]