Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Start process within other's environment
Forum Updated to NodeBB v4.3 + New Features

Start process within other's environment

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    moravas
    wrote on 15 Jan 2014, 08:25 last edited by
    #1

    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

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 15 Jan 2014, 08:34 last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dheerendra
        Qt Champions 2022
        wrote on 15 Jan 2014, 09:04 last edited by
        #3

        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");@

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • M Offline
          M Offline
          moravas
          wrote on 15 Jan 2014, 17:32 last edited by
          #4

          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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dheerendra
            Qt Champions 2022
            wrote on 15 Jan 2014, 18:04 last edited by
            #5

            Use QStringList procE = proc.systemEnvironment();

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0

            4/5

            15 Jan 2014, 17:32

            • Login

            • Login or register to search.
            4 out of 5
            • First post
              4/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved