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.

CheshireKat
  • 463
  • 3
  • 9
  • There are two separate questions here. You should probably split this question accordingly. http://stackoverflow.com/questions/412562/execute-a-terminal-command-from-a-cocoa-app?rq=1 may be relevant for the second question. – Anthony Geoghegan Dec 17 '15 at 12:40
  • Does the command live in a special location that needs a custom `$PATH` value? – Etan Reisner Dec 17 '15 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`. – Etan Reisner Dec 17 '15 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 – CheshireKat Dec 17 '15 at 13:25

1 Answers1

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

CheshireKat
  • 463
  • 3
  • 9