views:

1164

answers:

5

How can I perform the equivalent of shellexecute() in Lazarus for a Mac?

A: 

Since OS X is simply a descendant of BSD Unix, you can use fork() or exec(), whichever is appropriate for your application, IIRC. See the man pages on either of those for more info.

EDITED: Fixed typo to read "BSD Unix" instead of "Linux" and apologized in comments for fat fingers. :-)

Ken White
@Ken: That hurts, please make it say a descendant of BSD.
mghie
OS X is *not* Linux.
Chuck
Oops! Actually intended to type "Unix", which would be at least closer. Sorry, @mghie and @Chuck. :-(
Ken White
ShellExecute isn't just fork/exec. It looks up the program associated with a given document file and starts that program.
Rob Kennedy
+2  A: 

I don't know whether Lazarus libraries do already have this functionality wrapped, but if not you could write a conditionally compiled version of ShellExecute() using the info in the Launch Services Programming Guide.

mghie
A: 

I've successfully used Shell('open ' + Filename) in OS X 10.4 and 10.3 which seems to work rather nicely for most filetypes.

I stumbled across open at the shell prompt and now miss it in cygwin/linux etc.

RobS
+4  A: 

{ Here is code to do it. Use the TProcess object! }

uses Process;

...

procedure DoProcess;
Var
  Proc : TProcess;

Begin
  Proc := TProcess.Create(nil);
  try
    Proc.CommandLine := '/Applications/MyApp.app';

    PRoc.Options := Proc.Options + [poWaitOnExit];
    Proc.CommandLine := Proc.CommandLine + ' -someparam';
    PRoc.Execute;
  finally
    Proc.free;
  end;  
End;
A: 

fork hurts on Mac. BSDs use vfork, not fork.