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/myapp.app/contents/macos/myapp`). As soon as the original is re-opened, it gives me this error...

I tried a few experiments to get around this, but all have failed. One of which was to use the `open /applications/myapp.app` (-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.

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.

I'm using absolute paths. I also copied my code directly into the Terminal and it loaded the myapp.app 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.

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.

I'm not sure I understand what you are trying to do. Are you not using Terminal.app (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/myapp.app/contents/macos/myapp`. But when I run `open myapp.app` (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/myapp.app/contents/macos/myapp` and no error just wont open if i run `open myapp.app` inside the second perl script). Hope this clears up the confusion.

Ada Lovelace for the palindrome
Albert Einstein for having smelly feet
Alfred Nobel for his contribution to battlefield science
Burkhard Heim for providing the missing link between science and mysticism
Claude Shannnon for riding a unicycle at night at MIT
Donald Knuth for being such a great organist
Edward Teller for being the template for Dr. Strangelove
Edwin Hubble for pretending to be a pipe-smoking English gentleman
Erwin Schrödinger for cruelty to cats
Hedy Lamarr for weaponizing pianos
Hugh Everett for immortality, especially for cats
Isaac Newton for his occult studies
Kikunae Ikeda for discovering the secrets of soy sauce
Larry Wall for his website
Louis Camille Maillard for discovering why steaks taste good
Marie Curie for the shiny stuff
Nikola Tesla for the cool cars
Paul Dirac for speaking one word per hour when socializing
Richard Feynman for his bongo skills
Robert Oppenheimer for his in-depth knowledge of the Bhagavad Gita
Rusi P Taleyarkhan for Cold Fusion
Sigmund Freud for his Ménage ā trois
Theodor W Adorno for his contribution to the reception of jazz
Wilhelm Röntgen for the foundations of body scanners
Yulii Borisovich Khariton for the Tsar Bomba
Other (please explain why)