Hi guys, I'm trying to launch an app from Cocoa using NSTask, but I have a bedeviling problem. The application contains spaces (in this case I cannot change the name of the app so that is not an option) and NSTask is crashing when I pass a path containing spaces to it. I've tried everything I can think of including:
[serverTask setLaunchPath"/Applications/MAXON/CINEMA 4D R9/C4D Server PPC"];
[serverTask setLaunchPath"/Applications/MAXON/CINEMA\ 4D\ R9/C4D\ Server\ PPC"];
[serverTask setLaunchPath"/Applications/MAXON/CINEMA%204D%20R9/C4D%20Server%20PPC"];
and all those variations with
[serverTask setLaunchPath:[[NSWorkspace sharedWorkspace] fullPathForApplication"C4D Server PPC"]];
The errors I get are either
*** NSTask: Task create for path /Applications/MAXON/CINEMA 4D R9/C4D Server PPC failed: 8, "Exec format error".
or
*** Uncaught exception: <NSInvalidArgumentException>
*** -[NSCFDictionary setObject:forKey:]: attempt to insert nil value
which I don't understand at all since I'm not even using any dictionaries or collections of any kind. The code is extremely simple, it creates a task, sets the launch path, and launches it, that's it. Additionally, I know the rest of my code is fine because when I call
[serverTask setLaunchPath"/bin/ls"];
instead, it works fine. And I am quite sure I have the correct path and file name to the application (I started by dragging the app into Terminal and copied the path) -- see attachment below. Finally, launching the app from Terminal using "open" works fine as well. What do I need to do to format this path correctly? I know there has to be a way but I'm fresh out of ideas and I can't find any answers in the docs or from Google.
[serverTask setLaunchPath"/Applications/MAXON/CINEMA 4D R9/C4D Server PPC"];
[serverTask setLaunchPath"/Applications/MAXON/CINEMA\ 4D\ R9/C4D\ Server\ PPC"];
[serverTask setLaunchPath"/Applications/MAXON/CINEMA%204D%20R9/C4D%20Server%20PPC"];
and all those variations with
[serverTask setLaunchPath:[[NSWorkspace sharedWorkspace] fullPathForApplication"C4D Server PPC"]];
The errors I get are either
*** NSTask: Task create for path /Applications/MAXON/CINEMA 4D R9/C4D Server PPC failed: 8, "Exec format error".
or
*** Uncaught exception: <NSInvalidArgumentException>
*** -[NSCFDictionary setObject:forKey:]: attempt to insert nil value
which I don't understand at all since I'm not even using any dictionaries or collections of any kind. The code is extremely simple, it creates a task, sets the launch path, and launches it, that's it. Additionally, I know the rest of my code is fine because when I call
[serverTask setLaunchPath"/bin/ls"];
instead, it works fine. And I am quite sure I have the correct path and file name to the application (I started by dragging the app into Terminal and copied the path) -- see attachment below. Finally, launching the app from Terminal using "open" works fine as well. What do I need to do to format this path correctly? I know there has to be a way but I'm fresh out of ideas and I can't find any answers in the docs or from Google.