PDA

View Full Version : After setting environment, QProcess::start() no effect.



aaron
3rd September 2009, 11:42
Dear all,
I have a new question for QProcess, my Qt's verison is Qt4.3.
I want to run a program by QProcess, the program need to soure env before running it.
In my program, I do like below:
QProcess *proc = new QProcess();
QStringList env = QObject::systemEnvironment();
env<<"~azhang/env/tool.env" ; // run the program need soure it.
proc->setEnvironment(env);

QStringList args;
args<<file1<<file2
proc->start(proc,args );

When I do this, the program can not be started, and the errorcode is 5 (unknow error).
So, where is my wrong?
Please help, thanks!

yogeshgokul
3rd September 2009, 11:59
env<<"~azhang/env/tool.env" ; // run the program need soure it.

This is wrong way to add an environment.
You should provide a key=value pair.
So better do something like this :

env << "TMPDIR=C:\\MyApp\\temp";

aaron
4th September 2009, 02:56
Dear yogeshgokul,
Thank you !
I have ever set the env like : env <<"PATH = /home/azhang/env/tool.env" ,
but the result is same. Why?

yogeshgokul
4th September 2009, 06:56
Dear yogeshgokul,
Thank you !
I have ever set the env like : env <<"PATH = /home/azhang/env/tool.env" ,
but the result is same. Why?
Its hard to decide upon little information.
What if you add that path permanently in path variable using command promt or terminal and not with qt app itself ?
I just wanna be sure that adding
home/azhang/env/tool.env" in path is making any difference anyway.

wysota
4th September 2009, 10:10
I have ever set the env like : env <<"PATH = /home/azhang/env/tool.env" ,
but the result is same. Why?

Setting PATH before running QProcess has little sense. What are you trying to obtain this way? Because the only thing I can think about is that you'll be running bash to execute a script that runs some other programs which are not in the system path - but then you could have set that path directly in the script itself.

Besides, "/home/azhang/env/tool.env" doesn't look like a directory name, it's more likely a file, so setting it to PATH doesn't make sense.

ChrisW67
5th September 2009, 07:34
I have ever set the env like : env <<"PATH = /home/azhang/env/tool.env" ,
but the result is same. Why?
The space either side of the "=" sign may cause issues.

env << "TMPDIR=C:\\MyApp\\temp"; is good and

env << "TMPDIR = C:\\MyApp\\temp"; is probably not.