User forums > Using Code::Blocks

10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path

<< < (2/3) > >>

ProfessorO:
A search regarding the problem quickly led me to http://developer.apple.com/library/mac/#technotes/tn2002/tn2065.html , which made it easy to come up with a fix. Choose Settings / Environment ... from the menu, then edit the text box labeled "Terminal to launch console programs" to contain the following:


--- Code: ---osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script quoted form of "$SCRIPT"' -e 'end tell'
--- End code ---

All I did was add the quoted form of in the -e 'do script "$SCRIPT"' part. I hope this will make its way into the next update!

goetz:
I tested this on my Mac. For some reason there is an extra space at the end of the filename being executed. If I take out the last space (manually from the terminal window seeing the last command ran) then it works. Anything look wrong with this line? I copy and pasted it from the forum.


--- Code: ---osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script quoted form of "$SCRIPT"' -e 'end tell'
--- End code ---

Thanks,

Lawrence

ProfessorO:
Lawrence, I'm sorry to hear you're having trouble with this. I just double-checked this to make sure it's working on my Mac, and I tried it yesterday on a student's Mac. It works exactly as posted.

The symptoms you're reporting lead me to suspect you have a space inside the double quotes enclosing $SCRIPT, something like this: ... quoted form of "$SCRIPT "' ..., and if you take that space out, this should work. Another possibility is that you have a space at the end of your program name (fileName .cpp), or somewhere in the settings that specify how to run the file (very unlikely, but possible).

Can you copy and paste the whole line in the "Terminal to launch console programs" text box in the Environment Settings dialog here so someone can check it? I don't frequent this forum, so if you want me to look at it, you should also PM/email me.

RO

ProfessorO:
If you want the Terminal to close when the program finishes, you can modify the command to read as follows:


--- Code: ---osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script (quoted form of "$SCRIPT") & "; exit"' -e 'end tell'
--- End code ---

This seems slightly less confusing to students, some of whom will otherwise end up with a BUNCH of Terminal windows open, and sometimes interact with an old instance of the program.

You also have to make sure you go into Terminal / Preferences in the menu, select the Settings icon, Shell tab, and under "When the shell exits:", pick "Close if the shell exited cleanly". This also allows you to change the semicolon (;) to the AND operator (&&) and control whether the window closes via the return value from main (return 0; -> Terminal closes, while any non-zero return value keeps the Terminal window open).

Of course, this is slightly inconsistent--it's not the same as the behavior under Windows (and I haven't tested it under Linux, so I don't know how it differs). Since cb_console_runner doesn't seem to exist in the Mac OS X version of C::B, here's an alternative:


--- Code: ---osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script (quoted form of "$SCRIPT") & "; echo \'Press any key to continue.\'; read -n 1; exit"' -e 'end tell'
--- End code ---

It shows that big "ugly" command in the Terminal window, but at least the behavior is consistent with C::B's behavior under Windows (and what students seem to expect nowadays ... suppressing a rant about "kids" who learn to program only using IDEs and GUIs ... there, I'm all better now). ;-)

jthomas:
My students and I experienced the same problem, so I initially tried something very similar to what was proposed by ProfessorO above:

--- Quote from: ProfessorO on January 25, 2011, 03:16:14 am ---
--- Code: ---osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script quoted form of "$SCRIPT"' -e 'end tell'
--- End code ---

All I did was add the quoted form of in the -e 'do script "$SCRIPT"' part. I hope this will make its way into the next update!

--- End quote ---


But, as goetz reported, a trailing space in the contents of the $SCRIPT variable made this not work for me.


To get Code::Blocks to allow spaces in the names of files and folders, I had to use bash string manipulation. Also, because I noticed that the working directory is defaulting to the user's home directory when using the "do script" command (not desirable), I added a command to cd to the project's root directory. Finally, because seeing the entire command appear twice at the top of the terminal window is pretty messy, it also scrolls the text out of view using clear. This makes it so the output of the program is the only thing seen (unless the user scrolls up). The resulting command looks like this:

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


My students have reported success using it so far, so give it a try if you're having difficulty. =)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version