Author Topic: 10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path  (Read 24257 times)

Offline gamradtk

  • Single posting newcomer
  • *
  • Posts: 5
10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path
« on: September 07, 2010, 02:39:00 am »
I am new to Mac and I am even newer to Code::Blocks

When I select Build & Run I get the following message in the Build Log window:

Checking for existence: /Volumes/KAG HDB/Classes/test
Executing: osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "/Volumes/KAG HDB/Classes/test"' -e 'end tell'  (in /Volumes/KAG HDB/Classes)
Process terminated with status 0 (-6292 minutes, -20 seconds)
 
When the terminal window pops up I get the following message:

Last login: Mon Sep  6 19:01:21 on ttys000
/Volumes/KAG HDB/Classes/test
KAG-MAC:~ ken$ /Volumes/KAG HDB/Classes/test
-bash: /Volumes/KAG: No such file or directory
KAG-MAC:~ ken$

Notice that the path listed stops at the space after KAG.

If I move the program to a path without spaces everything runs properly.

Checking for existence: /Users/ken/Desktop/test
Executing: osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "/Users/ken/Desktop/test"' -e 'end tell'  (in /Users/ken/Desktop)
Process terminated with status 0 (-6266 minutes, -19 seconds)
 
Last login: Mon Sep  6 19:27:21 on ttys000
/Users/ken/Desktop/test
KAG-MAC:~ ken$ /Users/ken/Desktop/test
               Hello
KAG-MAC:~ ken$

Any ideas are greatly appreciated.

Offline gamradtk

  • Single posting newcomer
  • *
  • Posts: 5
Re: 10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path
« Reply #1 on: September 07, 2010, 03:11:31 am »
If I run the executable (outside of Code::Blocks) that was generated by the build process it works properly.

Last login: Mon Sep  6 19:59:43 on ttys001
KAG-MAC:~ ken$ /Volumes/KAG\ HDB/Classes/test ; exit;
               Hello
logout

[Process completed]

Offline BCCISProf

  • Multiple posting newcomer
  • *
  • Posts: 60
    • Professor Langsam's Home Page
Re: 10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path
« Reply #2 on: September 07, 2010, 01:05:40 pm »
This is a well known issue on the Mac. I simply tell my students  not to use blanks anywhere in the path.

Other Mac problems that seem not to have been fixed:
a. Printing from CodeBlocks hangs CodeBlocks.
b. Inability to change many settings within the editor settings window.

If anyone has a solution to the above, please let me know.

Workaround for a: Instead of printing, export to pdf and print the pdf.

Offline gamradtk

  • Single posting newcomer
  • *
  • Posts: 5
Re: 10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path
« Reply #3 on: September 07, 2010, 02:46:17 pm »
I am setting up 3 new iMacs in a computer lab for student use so this information is greatly appreciated.

Any additional words of wisdom for a newbie (both Mac and Code::Blocks) is also greatly appreciated.

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: 10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path
« Reply #4 on: September 07, 2010, 09:06:46 pm »
Patches are of course greatly appreciated too...

The keybindings and debugger should have been fixed now (p1), but some of the other issues remain (e.g. batch building from command-line can also crash the program)

Offline ProfessorO

  • Single posting newcomer
  • *
  • Posts: 3
Easy fix - please incorporate into the next update!
« Reply #5 on: January 25, 2011, 03:16:14 am »
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'

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!

Offline goetz

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: 10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path
« Reply #6 on: January 26, 2011, 11:26:22 pm »
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'

Thanks,

Lawrence

Offline ProfessorO

  • Single posting newcomer
  • *
  • Posts: 3
Space after $SCRIPT (inside double quotes)?
« Reply #7 on: January 29, 2011, 01:06:13 am »
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

Offline ProfessorO

  • Single posting newcomer
  • *
  • Posts: 3
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'

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'

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). ;-)

Offline jthomas

  • Single posting newcomer
  • *
  • Posts: 3
Re: 10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path
« Reply #9 on: February 14, 2011, 05:02:05 am »
My students and I experienced the same problem, so I initially tried something very similar to what was proposed by ProfessorO above:
Code
osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script quoted form of "$SCRIPT"' -e 'end tell'

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!


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'


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

Offline jthomas

  • Single posting newcomer
  • *
  • Posts: 3
Re: 10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path
« Reply #10 on: February 14, 2011, 05:06:45 am »
Also, I like ProfessorO's idea to have the Terminal window emulate the Windows behavior of closing when the program finishes (as soon as the user presses a key). With this behavior added, the command I posted above becomes this:
Code
osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "exe=\'$SCRIPT\'; cd \\"${exe%/*/*/*}\\"; clear; \\"${exe% }\\"; echo \'Press any key to continue.\'; read -n 1; exit"' -e 'end tell'


Yes, it's ugly, but I like that it makes for a fairly consistent experience for students on different platforms. =)


Kudos to ProfessorO for the idea. Make sure you follow his directions on how to set the window's behavior to close on exit:
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".


If you also want Code::Blocks to be made the active application when your console application exits (normally, Terminal will remain as the active program and you have to manually return to Code::Blocks), you can use this launcher script:
Code
osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "exe=\'$SCRIPT\'; cd \\"${exe%/*/*/*}\\"; clear; \\"${exe% }\\"; echo -e \'Press any key to continue...\'; read -n 1; osascript -e \'tell app \\"CodeBlocks\\" to activate\'; exit"' -e 'end tell'
« Last Edit: February 14, 2011, 08:23:57 am by jthomas »

yunlongzzj

  • Guest
Re: 10.05 and Mac OS X 10.6.4 - Program won't run with spaces in path
« Reply #11 on: August 11, 2016, 05:18:25 am »
You are not authorized.
You can login using the 'root' user.