Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to pass a string to a parent script?



  • 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?



  • @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,



  • @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!



  • @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.



  • @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.



  • @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....


  • Lifetime Qt Champion

    Hi,

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


Log in to reply