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. How to pass a string to a parent script?
QtWS25 Last Chance

How to pass a string to a parent script?

Scheduled Pinned Locked Moved Unsolved General and Desktop
environment varscript
7 Posts 3 Posters 1.1k Views
  • 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.
  • 0 Offline
    0 Offline
    0...-5
    wrote on 4 Sept 2019, 13:16 last edited by 0...-5 9 Apr 2019, 13:16
    #1

    My problem is the following.
    I have an app that is started from a shell script. After an app is quit the script needs to get a string value my app dealt with. I was thinking a good solution would be to use environment variables, but unfortunately after my app is exited all variables that it has set using qsetenv or QProcessEnvironment::systemEnvironment().insert() become inaccessible even for a script application was started from. Any ideas?

    J 1 Reply Last reply 4 Sept 2019, 17:37
    0
    • 0 0...-5
      4 Sept 2019, 13:16

      My problem is the following.
      I have an app that is started from a shell script. After an app is quit the script needs to get a string value my app dealt with. I was thinking a good solution would be to use environment variables, but unfortunately after my app is exited all variables that it has set using qsetenv or QProcessEnvironment::systemEnvironment().insert() become inaccessible even for a script application was started from. Any ideas?

      J Offline
      J Offline
      JonB
      wrote on 4 Sept 2019, 17:37 last edited by JonB 9 Apr 2019, 17:38
      #2

      @0-5
      You won't be able to do it via environment variables. Simplest to "return" a string value from a process is simply write it to stdout, or to some file, and parent shell script can receive it into a variable or do whatever with it,

      0 1 Reply Last reply 5 Sept 2019, 06:56
      4
      • J JonB
        4 Sept 2019, 17:37

        @0-5
        You won't be able to do it via environment variables. Simplest to "return" a string value from a process is simply write it to stdout, or to some file, and parent shell script can receive it into a variable or do whatever with it,

        0 Offline
        0 Offline
        0...-5
        wrote on 5 Sept 2019, 06:56 last edited by
        #3

        @jonb
        Parsing stdout or file is not as nice as checking env.var. But if there is no other solutions I have to do it. Thank you!

        J 1 Reply Last reply 5 Sept 2019, 07:14
        0
        • 0 0...-5
          5 Sept 2019, 06:56

          @jonb
          Parsing stdout or file is not as nice as checking env.var. But if there is no other solutions I have to do it. Thank you!

          J Offline
          J Offline
          JonB
          wrote on 5 Sept 2019, 07:14 last edited by
          #4

          @0-5
          You're not "parsing" stdout. You're just taking its value. E.g. bash script line

          var=$( command )
          

          looks pretty simple to me. Since there is no way of having a sub-process alter the environment variables of the parent, it's moot as to whether you would prefer it.

          0 1 Reply Last reply 5 Sept 2019, 08:02
          0
          • J JonB
            5 Sept 2019, 07:14

            @0-5
            You're not "parsing" stdout. You're just taking its value. E.g. bash script line

            var=$( command )
            

            looks pretty simple to me. Since there is no way of having a sub-process alter the environment variables of the parent, it's moot as to whether you would prefer it.

            0 Offline
            0 Offline
            0...-5
            wrote on 5 Sept 2019, 08:02 last edited by
            #5

            @jonb
            Unfortunately my app uses stdout to output a lot of stuff, not only the string I'm going to use. And so do 3rd party libs.

            J 1 Reply Last reply 5 Sept 2019, 08:06
            0
            • 0 0...-5
              5 Sept 2019, 08:02

              @jonb
              Unfortunately my app uses stdout to output a lot of stuff, not only the string I'm going to use. And so do 3rd party libs.

              J Offline
              J Offline
              JonB
              wrote on 5 Sept 2019, 08:06 last edited by JonB 9 May 2019, 08:08
              #6

              @0-5
              So then clearly stdout is not where your app should "return" its value. Maybe stderr, maybe some other file handle number, looks like you might be happiest with send to file in this situation to avoid ambiguity.

              What else would you like us to say? You can't do it via environment variables, and you can't get a string from the integer return result of a process, so....

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 5 Sept 2019, 20:16 last edited by
                #7

                Hi,

                If your output follows a known pattern then parse stdout to extract what you want.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                7/7

                5 Sept 2019, 20:16

                • Login

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