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

**URL:** <https://forum.juce.com/t/file-startasprocess-doesnt-work-if-arguments-are-provided/10986>\
**Category:** MacOSX and iOS\
**Created:** [August 12, 2013, 3:49pm UTC](https://forum.juce.com/t/file-startasprocess-doesnt-work-if-arguments-are-provided/10986 "2013-08-12T15:49:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [August 12, 2013, 3:49pm UTC](https://forum.juce.com/t/file-startasprocess-doesnt-work-if-arguments-are-provided/10986/1 "2013-08-12T15:49:16Z")

</div>

I’ve been putting together a simple launcher app for a [game jam I’m hosting](http://forums.tigsource.com/index.php?topic=31996.0), 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](http://stackoverflow.com/questions/3331401/comparing-different-the-launching-cocoa-app-with-parameters-methods), [2](http://stackoverflow.com/questions/3332049/how-to-use-nsworkspace-launchapplicationaturl)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 12, 2013, 4:15pm UTC](https://forum.juce.com/t/file-startasprocess-doesnt-work-if-arguments-are-provided/10986/2 "2013-08-12T16:15:13Z")

</div>

Ok, thanks - try it again now…

---

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [August 12, 2013, 6:58pm UTC](https://forum.juce.com/t/file-startasprocess-doesnt-work-if-arguments-are-provided/10986/3 "2013-08-12T18:58:40Z")

</div>

Yeah, that works perfectly. Cheers!

---

<div class="post-metadata">

**Author:** ![liamtmlacey](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/liamtmlacey/32/82_2.png) [@liamtmlacey](https://forum.juce.com/u/liamtmlacey)\
**Post date:** [August 13, 2013, 5:32pm UTC](https://forum.juce.com/t/file-startasprocess-doesnt-work-if-arguments-are-provided/10986/4 "2013-08-13T17:32:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 13, 2013, 8:08pm UTC](https://forum.juce.com/t/file-startasprocess-doesnt-work-if-arguments-are-provided/10986/5 "2013-08-13T20:08:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![liamtmlacey](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/liamtmlacey/32/82_2.png) [@liamtmlacey](https://forum.juce.com/u/liamtmlacey)\
**Post date:** [August 18, 2013, 2:04pm UTC](https://forum.juce.com/t/file-startasprocess-doesnt-work-if-arguments-are-provided/10986/6 "2013-08-18T14:04:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![benkuper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benkuper/32/899_2.png) [@benkuper](https://forum.juce.com/u/benkuper)\
**Post date:** [July 20, 2019, 8:16pm UTC](https://forum.juce.com/t/file-startasprocess-doesnt-work-if-arguments-are-provided/10986/7 "2019-07-20T20:16:16Z")

</div>

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 ?

Thanks
