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. Sourcing a bash script from QT application
QtWS25 Last Chance

Sourcing a bash script from QT application

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 906 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.
  • A Offline
    A Offline
    ahtarek
    wrote on 30 May 2021, 11:36 last edited by
    #1

    I am new to Qt. I want to run a bash script that exports some environmental variables then using the exported variables in my qt application . I am able to get environmental variables using QprocessEnvironment. The problem is I can't source the script and running using Qprocess::execute or Qprocess::startdetached() does not export the variables

    J 1 Reply Last reply 30 May 2021, 11:55
    0
    • A ahtarek
      30 May 2021, 11:36

      I am new to Qt. I want to run a bash script that exports some environmental variables then using the exported variables in my qt application . I am able to get environmental variables using QprocessEnvironment. The problem is I can't source the script and running using Qprocess::execute or Qprocess::startdetached() does not export the variables

      J Offline
      J Offline
      JonB
      wrote on 30 May 2021, 11:55 last edited by JonB
      #2

      @ahtarek
      This has nothing to do with Qt. You cannot run a subprocess in Linux which affects the environment variables in the program which executes it. source is a builtin command in bash which executes in the bash and does not create any subprocess.

      In order to change the values of environment variables in (say) a Qt program you need to change the environment variables in that program (e.g. Qt has qputenv()). You might read the lines from a (script) file, but you would have to "parse" it so that you can make calls to update the environment from within the program.

      This does assume you want the environment changed in the calling Qt program itself. If you only want to have those variables so that you can QProcess something else, you might consider instead executing a command which sources them followed by executing the command, like

      process.start("/bin/bash", { "-c", "source script && run some command" });
      
      1 Reply Last reply
      3
      • U Offline
        U Offline
        ussef
        wrote on 18 Dec 2022, 19:56 last edited by
        #3

        Just launch the Qt Creator app from the terminal and everything will work fine!

        1 Reply Last reply
        0

        • Login

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