QProcess and environment



  • Hello

    My question: how can I have a process executed within the user's default bash environment? Currently, if I open a terminal, the correct program launches due to paths exported from .bash_profile. However, this is not the case when executing the command via QProcess. Similarly, if I have aliases under .bash_profile or .bashrc, they are not recognized when executed directly by a process. I have also attempted to launch a shell first and execute the alias within that, but again the alias was not recognized:
    @
    process.start("bash");
    process.waitForStarted();
    process.write("foo test.py\n");
    process.write("exit\n");
    process.waitForFinished();
    @
    where alias foo='/Library/Frameworks/Python.framework/Versions/2.6/bin/python' is defined in .bashrc.

    The motivation:
    I am using QProcess to launch a python script from within Qt. As the script requires the import of certain modules, I would like to simply call the command 'python' and make it the users responsibility that the correct version of python is called (with other fixes to come later). Solving this will be of use in other projects as well - basically whenever I want to assume a program is installed without hunting for it.


  • Moderators

    I can't remember offhand, but with using bash in this scenario, do you need to pass in a -i or -l flag? I know bash has rules about which config files are read based on whether it's an interactive, a login, or non-interactive shell. (See man bash for more info.)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.