I'm trying to run a command via QProcess but it's not working. My command is something like utility -someflag /path/to/file. utility is in the PATH, however it seems QProcess is not using this environment variable.
The command simply fails and I need to specify the full path of the utility (which I'd like to avoid).
Is there any way around this? Basically some way to make QProcess use the PATH variable?
So the problem is that it depends on how the application is started. This is on OSX but it might be similar in other platforms:
If it's a command line application and started from a terminal then it will have access to the env variables.
If it's started from Qt Creator, it will not have access to any env variable.
If it's a GUI application (.app), it will not have access to the env variables.
The solution in my case, since it is a GUI application, was to update the .app package manually. First the file Info.plist needs to be changed from this:
<key>CFBundleExecutable</key>
<string>MyApplication</string>
to this:
<key>CFBundleExecutable</key>
<string>MyApplication.sh</string>
Then, still in the app package, in Contents/MacOS, create a new file with the same name as the application, but with a .sh extension, eg. "MyApplication.sh". Then create the launcher:
#!/bin/sh
SCRIPT_DIR=$(dirname "$0")
source ~/.bash_profile
logger "$SCRIPT_DIR/MyApplication"
exec "$SCRIPT_DIR/MyApplication" $#
The source ~/.bash_profile line in particular ensures that all the environment (including PATH variable) will be set properly.
Related
I previously asked a similar question with regards to cloud9, but I am now trying to do the same project in parallel on my windows 10 machine because I will not have internet access to use cloud9. I am trying to set up the configuration in preparation for following Daniel Kehoe's learn-rails tutorial book, but I am having trouble setting up the environment variables. The book seems to explain how to do it on Mac but I can not find the file in the atom editor. the book says to type the command:
atom ~/.bash_profile
However this just creates a new file that is not part of my rails app project directory. i have also tried
atom ~/.bashrc
which is the alternative but with the same result. It just creates a file unrelated to my project. The file is supposed to already exist somewhere.
I am supposed to put the environment variables into a file called ".bashrc" but I don't know where to find this file as it is hidden. How can I locate and open this file with Atom text editor?
.bashrc , .bash_profile are used in unix based operating systems for the terminal. In windows you set environment variables differently. In windows 10, search for environment variables in start menu, and select Edit the system environment variables and set them from there.
PS: You can have .bashrc if you have installed something like git bash, cygwin bash or bash for windows 10 or something else. And all 3 handle .bashrc differently.
Typing echo ~ in the Git Bash terminal will tell you where that folder is which contains the .bashrc file
I recently installed homebrew-cask and one of the things that I see is that it installs applications by default into the following directories:
Versioned package downloads => /opt/homebrew-cask/Caskroom/
Example : /opt/homebrew-cask/Caskroom/pdftk/2.02
Application binaries/libraries => /opt/
Example : /opt/pdftk/bin/
Instead of using the /opt directory, I would really like to use a directory located in /usr/local which is where my homebrew installation resides.
I can see from the docs that I can set an environment variable for #1, but I can't seem to figure out where to change #2.
I'd like to have the above two settings go to:
/usr/local/Caskroom/packages/pdftk/2.02
/usr/local/Caskroom/pdftk/bin
Any ideas on how I can change both settings or are there good ideas why I wouldn't want to do this?
Thanks.
From the Caskroom manual (specifically the Usage manual) you can change where the actual application will be installed by adding a line like this to your .bash_profile or .zshenv etc.
# Specify your defaults in this environment variable
export HOMEBREW_CASK_OPTS="--appdir=/Applications --caskroom=/usr/local/Caskroom"
I was having some trouble installing the gem libv8. Apparently I need to have python installed. I installed Python and was attempting to update my path with command from another forum:
SET PATH=C:[Ruby Directory]\bin;C:[Python Directory]
or in my case:
SET PATH=C:\Ruby192\bin;C:\Python27
I am not strong with paths and I can't figure out what I did. Now my environment can't find my Ruby directory.
Can someone explain what I did and how I might fix it?
That is most likely because your PATH variable already had a bunch of stuff that you simply throwed away with that line:
echo %PATH%
# a bunch of stuff
SET PATH=C:\Ruby192\bin;C:\Python27
echo %PATH%
# C:\Ruby192\bin;C:\Python27
You can try to append to it instead instead:
set PATH=%PATH%;C:\Ruby192\bin;C:\Python27
echo %PATH%
# a bunch of stuff plus C:\Ruby192\bin;C:\Python27
This change will be avalid for your terminal session only. Closing it and open again should restore the default path. If you need to make it permanent, you need to change your path throught the windows (for example, following this instructions)
When I run targets on ant it says it is unable to locate the variable I passed to it.
Config for environment variables :
in build.xml
<property environment="Env"/>
but I am unable to find the parameter defined parameter with
${Env.CATALINA_HOME}
where in the .bash_profile
export CATALINA_HOME=/Users/olgunkaya/development/apache-tomcat-7.0.34
and export PATH=${PATH}:$CATALINA_HOME
What can I do to achive this ?
Before you run ant, check to see if CATALINA_HOME is actually defined as an environment variable. I bet you'll find it isn't. Ant doesn't read your .profile or .bash_profile before starting, so if it's not already defined in your environment, Ant won't see it.
As you've seen opening a terminal window on a Mac doesn't necessarily guarantee that the .bash_profile file is executed. Try setting up these environment variables in .bashrc file instead.
Or, you can force .bash_profile to run by setting it as the Startup file in Terminal. Select File->Preferences from the menu, go to the Shell tab, select your default shell, and then click the Run Command checkbox and put .bash_profile in there. That will guarantee that .bash_profile is executed with each new terminal window.
I had a similar problem when referencing a custom variable, which was definitely defined in the shell spawning ant.
The solution was to EXPORT the variable when defined (in ~/.profile), so the shell would pass it to its children.
I am following the tutorial : http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html
when I reach the part where I am supposed to set the library path :
Unix or Linux:
LD_LIBRARY_PATH=`pwd`
export LD_LIBRARY_PATH
Windows NT/2000/95:
set PATH=%path%;
Neither of these work in cygwin. I keep getting an error when trying to run my program.
Cygwin doesn't use LD_LIBRARY_PATH, it looks for shared libraries in PATH, so try:
export PATH=`pwd`:$PATH
That will add the current directory to the front of the PATH.
Is that
LD_LIBRARY_PATH=$(pwd)
and you just messed up the html, or are you really running:
LD_LIBRARY_PATH=pwd
If the latter, try adding the $() to get the current working directory into the path. Also, you can
echo $LD_LIBRARY_PATH
to ensure it contains what you want. You might consider doing
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)
to avoid discarding previous contents of the path.