Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 21, 2011, 03:21 PM   #1
Duke Leto
macrumors regular
 
Join Date: Mar 2008
Command Line Tool Executable from Finder?

I made a project in C that was a "command line tool" in XCode. It uses GLUT/OpenGL, so it does have a user interface. It works fine, and I can run it from Terminal, but I was wondering if there was any way to allow it to run from Finder.

I did create a new target (a Cocoa application), and I included the linked frameworks and removed the prefix header and it compiles and runs. However, it won't work from Finder. I think that the problem is that my program relies on a file named "Input" that it assumes is in its directory. I tried using
Code:
FILE* data = fopen("../../Input", "r");
instead of
Code:
FILE* data = fopen("Input", "r");
but that didn't work. (I also tried more levels of up and down, that doesn't seem to work either.)

I hope that that ramble was half-intelligible!

Thanks in advance for any help.
__________________
Gravita - a gravity simulation.
Available for Mac at http://www.thebluekoala.com
Duke Leto is offline   0 Reply With Quote
Old Apr 21, 2011, 04:16 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
In both cases of fopen(), you are assuming a particular value for current working directory, and from which your relative pathnames are assumed to be sensible.

I suggest checking your assumption of working directory, perhaps by NSLog()'ing the actual value, such as returned by the C function getcwd(). You should read the man page for getcwd() to see what its parameters are.
chown33 is offline   0 Reply With Quote
Old Apr 21, 2011, 05:48 PM   #3
Duke Leto
Thread Starter
macrumors regular
 
Join Date: Mar 2008
I looked into getcwd, and I was able to get the directory of the executable. I wrote some code to modify the path to go up a couple of folders, and I verified that it did the correct modifications. Furthemore, I found that the program worked just fine when I opened the package contents of the .app file and ran the executable inside the MacOS folder from Terminal.
However, the .app will not run from Finder.
__________________
Gravita - a gravity simulation.
Available for Mac at http://www.thebluekoala.com
Duke Leto is offline   0 Reply With Quote
Old Apr 21, 2011, 07:13 PM   #4
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by Duke Leto View Post
I looked into getcwd, and I was able to get the directory of the executable. I wrote some code to modify the path to go up a couple of folders, and I verified that it did the correct modifications. Furthemore, I found that the program worked just fine when I opened the package contents of the .app file and ran the executable inside the MacOS folder from Terminal.
However, the .app will not run from Finder.
Running the executable using Terminal, after cd'ing into the .app Contents/Resources is not the same thing as running it from Finder.

You should look at the working directory when run from Finder, using the debugger if you have to.

You're making a faulty generalization based on what happens in Terminal. In particular, I can almost guarantee that launching from Finder DOES NOT set the working directory to the location of the executable.
chown33 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
better touch tool command anonymous4a Mac Applications and Mac App Store 0 Mar 11, 2014 10:38 AM
command tool for mac osx syntax.syntax OS X Mavericks (10.9) 13 Feb 14, 2014 06:09 PM
General: iOS7 command line... Equivalent of "say" command? RobertoG Jailbreaks and iOS Hacks 0 Jan 19, 2014 05:05 PM
Need Command-line help EricBrian Community Discussion 1 Feb 20, 2013 08:40 PM
excecuting a command line tool from Terminal Mark FX Mac Programming 3 Dec 6, 2012 02:46 PM

Forum Jump

All times are GMT -5. The time now is 09:43 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC