Start process within other's environment
I write a little tool that execute two scripts automatically. The modification of the scripts are not allowed.
The first script set some environment variables that are used by the second script. The problem is that I create and execute different processes to run those. How can I start the second process in same environment as the first, or is there any possibility to "export" the environment of the first process and "import" into another?
are you using QProcess to start your scripts?
If so take a look at "QProcess::setProcessEnvironment()":http://qt-project.org/doc/qt-4.8/qprocess.html#setProcessEnvironment
You will have to test if the processEnvironment() of the first process also contains the variables which are set by the script.
Otherwise you should call the second script script with the same QProcess instance.
Following code snippet may help you. Enjoy
@QProcess *proc = new QProcess;
QProcess *proc2 = new QProcess
I want to try out to query the environment variables with the following code:
process.setProgram("senv.cmd"); process.setArguments(args); process.open(); qDebug() << process.processEnvironment().toStringList(); process.waitForFinished(-1);
but nothing happened. I think, if I cannot query the enviroment of a process than... Can somebody tell me, what I made wrong?
Use QStringList procE = proc.systemEnvironment();