在Mac上,我该如何执行与shellexecute()
相当的操作?
{这里是实现的代码。使用TProcess对象!}
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;
如果您想使用ShellExecute打开一个文档并使用其首选应用程序,那么可以使用LCLIntf单元中的OpenDocument过程。
Lazarus转换工具也使用这个替代ShellExecute的方法,请参见Lazarus wiki。在内部,它使用RobS提到的open命令。
在 Mac 上使用 fork 会有问题。BSD 使用 vfork,而不是 fork。
我已经成功地在OS X 10.4和10.3中使用了Shell('open ' + Filename)
,该方法对于大多数文件类型似乎非常有效。
我在shell提示符下偶然发现了open
,现在在cygwin/linux等中也想用它。