Author Topic: Execution Working Directory for Mac?  (Read 9379 times)

RyanLeiTaiwan

  • Guest
Execution Working Directory for Mac?
« on: March 31, 2009, 03:17:06 am »
Hi all, I was trying to build and run my project containing three .c and three .h files.
The imread() function reads a BMP image in the current directory, and it runs OK with command-line:
> gcc -Wall -o project matrix.c util.c image.c

But after I tryed C::B by putting sources, project file, debug output dir. all in one directory,
say /Users/user/code, with no extra bin/ and obj/, the execution becomes:
imread(): File open error.


Clearly this is the message I wrote when the BMP is not found.
But it works OK again if I use TERMINAL to cd to ~/code, where the BMP resides, then run ./project myself.
I wonder if it's the problem of my own configurations, or something is wrong with the C::B build message:
Executing: osascript -e 'tell app "Terminal" to do script "/Users/user/code/project "'  (in /Users/user/code)

It seems to be runnung my project directly from my home directory (terminal default), even if I changed the
"Execution working dir." to absolute path: /Users/user/code in "project properties".
In this case, it sure cannot see the BMP file.
Of course, it works again when I copy the BMP to home, but this is unnatural and is still not correct for my purpose.

I know the Mac version is still new, and so am I to C::B, so hope someone can tell who is wrong.
Thanks in advance.

Ryan.
« Last Edit: March 31, 2009, 03:30:54 am by RyanLeiTaiwan »

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Execution Working Directory for Mac?
« Reply #1 on: March 31, 2009, 02:06:11 pm »
It sets the working directory (wxSetWorkingDirectory) before starting Terminal, but then terminal defaults to the home directory again. Presumably the generated $SCRIPT should have a cd command embedded before the execution or something.

Or you could change your program to find the resources relative to the executable, like it's usually being done on Mac OS X.

salo9000

  • Guest
Re: Execution Working Directory for Mac?
« Reply #2 on: May 18, 2009, 06:04:21 pm »
I have the same problem.

I've been working with C::B on linux and now I'm on a Mac and haven't found a workaround for this. Has someone found one?

Cheers.
Salomon.

Offline jthomas

  • Single posting newcomer
  • *
  • Posts: 3
Re: Execution Working Directory for Mac?
« Reply #3 on: February 14, 2011, 05:13:28 am »
Try the following launcher script (Settings menu -> Environment, and replace the bottom text box labeled "Terminal to launch console programs" with the command below):


Code
osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "exe=\'$SCRIPT\'; cd \\"${exe%/*/*/*}\\"; clear; \\"${exe% }\\""' -e 'end tell'


My students have reported success using it so far, so give it a try if you're having difficulty. It also allows you to have spaces in the name of your project and parent directories and clears the Terminal screen so that the only thing displayed is the output of the program. =)

jwns

  • Guest
Re: Execution Working Directory for Mac?
« Reply #4 on: October 07, 2013, 06:58:11 pm »
Try the following launcher script (Settings menu -> Environment, and replace the bottom text box labeled "Terminal to launch console programs" with the command below):


Code
osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "exe=\'$SCRIPT\'; cd \\"${exe%/*/*/*}\\"; clear; \\"${exe% }\\""' -e 'end tell'


My students have reported success using it so far, so give it a try if you're having difficulty. It also allows you to have spaces in the name of your project and parent directories and clears the Terminal screen so that the only thing displayed is the output of the program. =)

I'm using CodeBlocks on OSX 10.8.5; C::B Build Dec 27, 2012 wx2.8.12.

I've been experiencing the same problem as the OP. Terminal has been launching in my home directory instead of the directory containing the compiled executable.

I just tried jthomas' solution but it was not quite working as written. I had to modify the 'cd \\"${exe%/*/*/*}\\";' portion.
There were too many /* in his cd command.

Here is a the same command with my modifications. It's working in the current build.

Code
osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "exe=\'$SCRIPT\'; cd \\"${exe%/*}\\"; clear; \\"${exe% }\\""' -e 'end tell'