Start process within other's environment
-
Hi Folks,
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?Regards,
Norbert -
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;
proc->start("script1")
QProcess *proc2 = new QProcess
proc2->setProcessEnvironment(proc->processEnvironment());
proc2->start("script2");@ -
Hi,
I want to try out to query the environment variables with the following code:
@
QStringList args;
args.append("-p");
args.append(_ui->_CBsenv->itemText(_ui->_CBsenv->currentIndex()));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?
Regards,
Norbert -
Use QStringList procE = proc.systemEnvironment();