Is Command Line Parameters broken for Macintosh?

From our main application we are running the code to open our updater program. When we run the open and pass in the parameters like this:

f.Open " /"+sCode+" "+s

sCode just validates that our main program is calling the update program. The string s is just telling it what to do. I should be passing the string into the updater program. However, in the updater program, using this code:

Dim s as String  = System.CommandLine

s Does not contain the parameters I passed from the main program. It only contains the file location for the updater program. The parameters are not being passed in. This works fine on Windows. Is passing parameters with system.commandline broken on Macintosh?

A few ideas:

  • on macOS, f must be the app bundle, so if you do this:
var f as folderItem = app.ExecutableFile
f.open

nothing will happen.

• You need to get the app bundle which is 3 levels up, e.g.

var f as folderItem = app.ExecutableFile.parent.parent.parent
f.open

However, macOS, by default, won’t open multiple copies of the same app. If your app is self-updating and is the same app, you would nee to work around this using the “open -n” shell command.

Yes. F is the executable and it does open the updater program like it should. For the other part, my updater app is not inside of the app bundle. I sits on its own but in the same folder location. I have FundAccounting.app and separately FundUpdate.app. They both sit inside the FundAccounting (not app) folder.

Here is a sample of what is not working. Build each of the two projects into an executable. Then start the first app and type in some text. Press the button and it will open the second app and send the text as a parameter. When it opens the second executable, it will not read the command line.

With a few minutes of play, I found that by launching the inner executable you do get the parameters.

1 Like

I can confirm both findings.

  • I created the “second app” with a much older version (Xojo 2019R1.1) and I see the same issue: when calling FolderItem.Open() on the app bundle, command-line parameters are missing. So it’s not a new issue.
  • However, as @Tim_Parnell found, calling FilderItem.Open on the executable

f = f.child("Contents").child("MacOS").child("SecondApp")

the parameters are received.

Also, in my prior comment above I said that launching the executable (inside /Contents/MacOS/ would not launch the app; in fact, it does work, and appears to be the solution.

I think this is, at minimum, a documentation bug. Whether it’s an actual bug or not, I’m not sure.

If you open the app bundle from the terminal like this:

cd /path/to/my/apps
open SecondApp.app/ --args foobar1 foobar2 foobar3

Then you do get the parameters.

I think this argues that it is a Xojo bug, and could be fixed.