2

In my bash script i have:

program=*program_name*
condition=$(which $program 2>/dev/null | grep -v "not found" | wc -l)
if [ $condition -eq 0 ] ; then
echo "$program is not installed";
echo -n *mypass* |sudo -S gem install $program;
fi

First of all, it installs program every time. It shows that program is not installed, but i can use it from terminal.

...then, i need to use this program in my cocoa application, for example

program --help

Using

system([pathToFile UTF8String]);

i get:

path_to_bundle/myBashScript.sh: Permission denied // Where path is in bundle

path_to_folder/myBashScript.sh:line 30: program: command not found // Where path is from other system folder

Using NSTask i get program: command not found every time.

I don't understand why this is happening. And i would like to know how i can use this program in my cocoa app.

4
  • There are two separate questions here. You should probably split this question accordingly. stackoverflow.com/questions/412562/… may be relevant for the second question. Commented Dec 17, 2015 at 12:40
  • Does the command live in a special location that needs a custom $PATH value? Commented Dec 17, 2015 at 12:44
  • You can simplify that which test nonsense to if ! which program >/dev/null 2>&1; then or (better) if ! command -v program >/dev/null; then. Commented Dec 17, 2015 at 12:45
  • 1. No, there is only one question - why custom program is not visible from cocoa app, because i can execute normal bash commands like ls, grep and others. The problem is in bash script execution behavior. 2. There are multiple ways to check if app is installed. Neither method gave a positive result Commented Dec 17, 2015 at 13:25

1 Answer 1

1

So, i have found the solution.
When you're trying to run the custom system program from the cocoa app, you should give the full path to the binary.

The problem is in:

program=*program_name* 

*program_name* should be full path to binary, in my case it was /Library/Ruby/Gems/2.0.0/gems/program-version/bin/program

For additional information about installation paths: https://wiki.haskell.org/Mac_OS_X_Common_Installation_Paths http://help.rubygems.org/discussions/problems/739-how-to-run-applications-installed-by-gem

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.