【问题标题】:How can I perform the equivalent of shellexecute() in Lazarus for a Mac?如何在 Mac 的 Lazarus 中执行相当于 shellexecute() 的操作?
【发布时间】:2009-02-26 17:54:39
【问题描述】:

如何在 Mac 的 Lazarus 中执行 shellexecute() 的等效操作?

【问题讨论】:

    标签: delphi macos pascal lazarus


    【解决方案1】:

    { 这是执行此操作的代码。使用 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;
    

    【讨论】:

      【解决方案2】:

      我不知道 Lazarus 库是否已经封装了此功能,但如果没有,您可以使用 Launch Services Programming Guide 中的信息编写 ShellExecute() 的条件编译版本。 p>

      【讨论】:

        【解决方案3】:

        如果您想使用 ShellExecute 打开带有首选应用程序的文档,则可以使用 LCLIntf 单元中的 OpenDocument 过程。

        Lazarus 转换工具也使用此替换 ShellExecute,请参阅 Lazarus wiki。在内部,它使用 RobS 提到的 open。

        【讨论】:

          【解决方案4】:

          我已经在 OS X 10.4 和 10.3 中成功使用了Shell('open ' + Filename),这似乎对大多数文件类型都非常有效。

          我在 shell 提示符下偶然发现了open,现在在 cygwin/linux 等中错过了它。

          【讨论】:

            【解决方案5】:

            fork 在 Mac 上很痛。 BSD 使用 vfork,而不是 fork。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2015-01-19
              • 2013-01-07
              • 2011-05-03
              • 2016-02-14
              • 2010-09-12
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多