File::startAsProcess doesn't work if arguments are provided

I’ve been putting together a simple launcher app for a game jam I’m hosting, and I’ve found that File::startAsProcess doesn’t work on OSX if you try and launch a bundle and pass it arguments.

Disclaimer: my knowledge of objective c is minimal and it’s possible that the following contains various errors.

The problem seems to be that in Process::openDocument, you’re using openURLs when you detect that the passed-in fileName is a bundle. As far as I can tell though, this doesn’t run an executable with arguments, but rather attempts to run multiple executables. I believe the correct function for this purpose is launchApplicationAtURL:

[code]NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];

StringArray docs;
docs.addTokens (parameters, true);
NSMutableArray* paramArray = [[NSMutableArray alloc] init];
for (int i = 0; i < docs.size(); ++i)
[paramArray addObject: juceStringToNS (docs[i])];

[dict setObject:paramArray forKey:NSWorkspaceLaunchConfigurationArguments];
ok = [[NSWorkspace sharedWorkspace] launchApplicationAtURL: [NSURL URLWithString: juceStringToNS (fileName)]
options: NSWorkspaceLaunchDefault|NSWorkspaceLaunchNewInstance
configuration: dict
error: nil];
[/code](there seems to be an additional problem with your use of openURLs in that you never actually pass fileName to the function, but that’s a bit beside the point)

The above works perfectly for me. The only problem is that launchApplicationAtURL is only available for 10.6 and higher; I don’t know how much of an issue that is these days.

References: 1, 2

Ok, thanks - try it again now…

Yeah, that works perfectly. Cheers!

Hey Jules
The new code here does in fact create a compile error when trying to build for OS X 10.5.
Can this be fixed?

I don’t even have the 10.5 SDK any more… What’s the error?

Sorry I didn't get back to you regarding this issue - it completely slipped my mind.

The issue seems to be fixed now though, thanks.

Hey, still having the problem, latest JUCE develop branch :

  • on Windows, everything works fine, I can use startAsProcess() with or without additional parameters
  • on MacOS (tried with Sierra and Mojave), this will work with *.app files, but *.sh or *.cmd or executables like /path/to/my/file will only works if no arguments provided, otherwise it will just not do anything.

Any clue ?