Including and using a Unix Executable File

I’v got a unix executable file that I want to include in my project and use in my program.
So I drag it into the project. Then what? How do I run it?

If I run the file from disk, no problem. It is just a matter of setting the path and run it in a shell.
But if I want to do this right, where am I supposed to put it if Xojo doesn’t do it for me when draggin it into the project?
-And If I have to put it somewhere outside, then what is the point of dragging it into the project?

At first I figured that I could run it like this:
Dim s As New Shell
Dim cmd As String
cmd=“MyExecutableUnixFile etc etc”
s.Execute(cmd)

But it returns: error127 (This module is private, and can only be used within its containing module.)
What do I do about that?

[quote=151698:@Roger Jönsson]I’v got a unix executable file that I want to include in my project and use in my program.
So I drag it into the project. Then what? How do I run it?

If I run the file from disk, no problem. It is just a matter of setting the path and run it in a shell.
But if I want to do this right, where am I supposed to put it if Xojo doesn’t do it for me when draggin it into the project?
-And If I have to put it somewhere outside, then what is the point of dragging it into the project?

At first I figured that I could run it like this:
Dim s As New Shell
Dim cmd As String
cmd=“MyExecutableUnixFile etc etc”
s.Execute(cmd)

But it returns: error127 (This module is private, and can only be used within its containing module.)
What do I do about that?[/quote]

Since you talk about a Unix executable, I will guess it is a Mac OS X Program.

When you drag a file into the project, it is copied into the bundle, within the Resources folder. So you can execute it there, as long as it does not need to write to the disk in there.

Alternatively, you can copy it to a subfolder within SpecialFolder.ApplicationData where you run it.

rather than cmd with a fixed string, you may want to point a folderitem to that executable, and use something like :

cmd = f.shellpath+ "\\ myparameter1\\ myparameter2"

be sure that file permissions are set to allow execution.

I have been playing with this for hours. I haven’t got a clue what I am dealing with here. Searching, testing and no Idea what to do. This ought to be so easy…

If I do this:

Dim s As new Shell
Dim cmd As String

dim f as folderitem
f=app.ExecutableFile.Parent.Parent.Child(“Resources”).Child(“MyUnixExecutable”) 'found this somewhere…

cmd=f.nativepath+" /dev/disk3 1"

s.Execute(cmd)

-I get this path, which does not work in the terminal either (while app is still running):

/private/var/folders/dc/9sn4n3qd5b1gck8m6nbt_bpr0000gn/T/TemporaryItems/My Application.debug.app/Contents/Resources/MyUnixExecutable ’ (+ s.ErrorCode 127)

Using this works:

cmd="/Users/roger/Desktop/MyUnixExecutable /dev/disk3 1" 'With MyUnixExecutable on the desktop…

Does this have to do with file permissions? -If so, to what files and how do I cure it?
(I did try experimenting with f.Permissions = &o764 etc, but it did not change anything)
Does that long path I get seem reasonable?

MyUnixExecutable is only used to read (from /dev/disk3)

Sigh.
I was reading and testing, desperately searching and testing, testing, testing and somewhere along the way I lost track and forgot to again test with cmd=f.shellpath
Now it works.

[quote=151879:@Roger Jönsson]Sigh.
I was reading and testing, desperately searching and testing, testing, testing and somewhere along the way I lost track and forgot to again test with cmd=f.shellpath
Now it works.[/quote]

That is exactly what I posted for you, when you posted your original question 8 hours ago. If you read what people tell you, maybe you would waste less time…

The problem was that I did not understand what you meant and did not know what to do. I did read your message carefully several times.
Now when I solved it I better understand the process. But with the lack of info I had, I could not figure out what tools to use and how to use them. At the stages where I was trying to use shellpath it was not working for some reason (many things can go wrong) and in desperation I tried everything I could think of and now lastly when everything else was right I forgot to put it back one last time as I thought I had already tried it.

Sorry for being such an idiot. :frowning:

Okay, now you got it working, some things you’ll need to consider.

#1 Store it in a folder called “Helpers” in the contents folder. Resources is not the correct place and you may not be able to code sign your application.

#2 if you’re thinking of the App Store, you will have to use different code than the Xojo shell.

Thank you for the information!

#1 Ok. I think I will (wonder why Xojo does not place it there).

#2 I don’t think I am going waste time on getting my cd-player (or the other projects I am working on) approved by Apple. I am doing this for a hobby and I think I will release it for free. Even though I would love to se my program(s) spread and Apple Store would be a good place for that, spending more money and time to sell something for free makes no point.

There are two reasons why I started making a cdplayer for mac. There is no non bloated cd-player that does both gapless playing and detecting of pre-emphasis on track level. The only part I did not write myself is the detecting of that flag per audio track. The developer of XLD gave me a ready to use executable that does just that and this probably saved me a huge amount of time diving into the cd red book documentation. In order to read that flag we need to get access to the raw data of the audio cd. Finder and apple does it’s best to keep us from reading raw data. It can’t even be read with the terminal while the audio cd is mounted.
Most mac players and rippers (that even bothers with correct pre-emphasis processing so that these cd:s sound as they should) rely on a Table Of Content available on the cd:s. The problem is that the TOC is not always right. It didn’t use to be a problem with cd-players as they used to read from the info per track, but some early cd:s will sound very shrill with (all?) cd players on mac as they read the TOC or use itunes to play. Not even Itunes does this right and there are reports that the frequency response after processing (de-emphasis) is not perfectly flat either. Apple of course doesn’t give a shit and does it best to stop any others doing it right, by making it difficult to spread or run programs that they have not approved (made money on). The TOC (hidden file) available in the mounted audio cd folder, is a fake one and does not even give the right info on the pre-emphasis (the same that is available on the cd).

Would there even be any way, for anyone but Apple, to read the raw, unaltered, data from an audio cd and get it approved by them?
If not, then it is not possible for anyone but Apple to make a cd-player that always does it right and have it on Apple store anyway. And even they didn’t.

I understand your concern about the App Store, it can be a royal PITA some times, however if you want maximum exposure there is no better way than the App Store. Think of it like Carrefour, millions of people all visiting once place to find Mac apps.

If you design your application with the App Store in mind, it will make it trivial to release it there, also targeting the App Store will force you do things in a way that hopefully will reduce the likelihood of Apple enforcing a change that breaks your application.

Your main issue will be that you’ll need to Sandbox your application, I’ve not tried to access a CD from a Sandboxed application, but I suspect that this will need a special entitlement, or some creativeness.

The other issue you’ll face once your application is Sandboxed is that you will not able to communicate with the console application, unless it is also Sandboxed and you use NSTask to communicate with it. There are tools and code available for purchase to perform both these tasks, however you can do it all yourself.[quote=152100:@Roger Jönsson]#1 Ok. I think I will (wonder why Xojo does not place it there).[/quote]
Xojo doesn’t have an option for this and Apple only recently enforced it for code signing, I haven’t logged a feedback request for it either. In the mean time, what I do is to have a folder called “Helpers”, which I then use the copy files script to copy this folder (not the contents) into the “Contents” folder.

[quote=152102:@Sam Rowlands]
If you design your application with the App Store in mind, it will make it trivial to release it there, also targeting the App Store will force you do things in a way that hopefully will reduce the likelihood of Apple enforcing a change that breaks your application.[/quote]
Good points.

Or release a mutilated version of App Store, without the ability to detect pre-emphasis, with some sort of info (in the “About” menu") on the availability of a full version outside App Store. Would that pass inspection or is it not allowed?

I wonder, why would it matter to them if I place my file here or there or in another folder inside the package?

Because executable was always meant to go into certain folders, it’s just that Apple never enforced that guideline… Until they changed their code signing rules recently. So everyone that was doing it wrong got bitten!

And I figured that by placing it the way Xojo wanted to, I would be safe…