Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Mac OSX Opening .app & UNIX EXEC

by nevafuse (Novice)
on May 18, 2009 at 19:31 UTC ( #764709=perlquestion: print w/replies, xml ) Need Help??
nevafuse has asked for the wisdom of the Perl Monks concerning the following question:

For simplicity sake, I'm having a problem opening up a unix executable from another unix executable both perl scripts on OSX. I'm not particular familiar with Macs, but I have my hands tied. I have a .app folder in the Applications folder that links to my first unix executable (perl) in the contents/macos folder. This works fine. In the program, it launches another unix executable (perl) and closes itself. The second program runs for a little bit and then tries to re-open that original program in the contents/macos folder (with shell cmd `/application/`). As soon as the original is re-opened, it gives me this error...
Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000
I tried a few experiments to get around this, but all have failed. One of which was to use the `open /applications/` (-a and -n flags also tried) shell command which doesn't re-open the application at all (no error or anything).

If I run the first unix exec in the contents/macos by double-clicking the actual file (instead of double-clicking the .app folder in Applications) everything works fine. But unfortunately this is impractical for what I am trying to do.

Thanks in advanced for any help.

Replies are listed 'Best First'.
Re: Mac OSX Opening .app & UNIX EXEC
by paulchernoch (Acolyte) on May 18, 2009 at 21:21 UTC
    I am interested to the answer to this question, too, as I am also working on OS X.

    When I use the shell command "open" I always supply an argument that is a document file name, not an application file name. This causes the application bound to the file to be opened. That may be part of your problem. Another issue would be the current path. Your perl script can change the current working directory using function "chdir", which might help.

    Then there is your PATH environment variable. If any of the applications are in directories specified using a relative path, your CWD will certainly affect whether the app can be found.

    - Paul
      Hey Paul,

      I'm using absolute paths. I also copied my code directly into the Terminal and it loaded the fine. Also, the code runs fine if I run the main executable. It only has an issue when I run the .app folder. The .app folder must put some kind of lock on the main executable.
Re: Mac OSX Opening .app & UNIX EXEC
by jethro (Monsignor) on May 18, 2009 at 21:23 UTC

    I don't know much about OSX, but if I had to guess I would say someone is trying to dereference a NULL pointer.

    Since you don't show any code, I can't help you much. Try to move both programs to the same folder to see if paths have anything to do with it. Run a trace or debugger alongside. Call a copy of the first program somewhere else to see if the error depends on reopening the same file or if it is the contents that does the harm.

      I'm using absolute paths to reference both files, so unfortunately that isn't the issue. And the program runs fine if I run the executable instead of the .app, so my code must work fine. Running the .app must put a lock on the main executable. I just need to find out how to get around that.
Re: Mac OSX Opening .app & UNIX EXEC
by graff (Chancellor) on May 19, 2009 at 00:25 UTC
    I'm not sure I understand what you are trying to do. Are you not using (or X-Windows/xterm) to run a command-line shell? If not, why not? This is the normal unix way of running scripts or compiled programs and since macosx is just bsd unix with extra bells and whistles, it's the normal way I do stuff on the mac. I've never had a problem using perl from the shell.
      I'm running a shell command in my 2 perl script. Like I said in the post, the script works fine when I run `/Applications/`. But when I run `open` (mimicking someone double-clicking the .app folder) it doesn't work correctly. It loads the first application, and then loads the second app and closes the first app, but it won't re-load the first app (with an error if i run `/Applications/` and no error just wont open if i run `open` inside the second perl script). Hope this clears up the confusion.
Re: Mac OSX Opening .app & UNIX EXEC
by jhourcle (Prior) on May 19, 2009 at 15:27 UTC
    I tried a few experiments to get around this, but all have failed. One of which was to use the "open" shell command which doesn't re-open the application at all (no error or anything).

    Man pages are your friend:

    NAME open -- open files and directories SYNOPSIS open [-a application] file ... open [-b bundle_identifier] file ... open [-e] file ... open [-t] file ... open [-f]

    You want the -a flag

      "open" in the terminal works fine without the -a flag. But for testing reasons, I also compiled it with the flag and it still doesn't open (no error either).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://764709]
Approved by MidLifeXis
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2017-06-28 17:29 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (641 votes). Check out past polls.