从 OSX 终端打开应用程序并打印调试输出

从 OSX 终端打开应用程序并打印调试输出

我可以使用 打开一个应用程序open,如下所示:

open ./MyApp.app

但这并没有显示我需要的应用程序的调试打印输出。

如果我手动找到包内的二进制文件并运行它,我就能得到正常的打印输出,但我希望能够运行该应用程序。

答案1

。应用程序应用程序是目录,从终端打开可执行文件而不是整个目录,例如..

open /Applications/my.app/Contents/MacOS/my

如果你不确定应用程序内容中的可执行文件名,请检查my.app/Contents/Info.plist CFBundleExecutable

答案2

打开命令没有调试或详细标志。

您可以使用 查看应用程序的警告或错误输出console.app

控制台应用程序

或者,如果您的应用程序有调试或详细程度标志,您可以使用 将该标志传递给您的应用程序open --args。例如,Google Chrome 有标志--enable-logging --v=1可以打开调试并将输出保存到chrome_debug.logChrome 用户数据目录中。您可以使用以下选项启动 Google Chrome

open -a "Google Chrome" --args --enable-logging --v=1

open命令选项

 -a application
     Specifies the application to use for opening the file

 -b bundle_indentifier
     Specifies the bundle identifier for the application to use when open-
     ing the file

 -e  Causes the file to be opened with /Applications/TextEdit

 -t  Causes the file to be opened with the default text editor, as deter-
     mined via LaunchServices

 -f  Reads input from standard input and opens the results in the default
     text editor.  End input by sending EOF character (type Control-D).
     Also useful for piping output to open and having it open in the
     default text editor.

 -F  Opens the application "fresh," that is, without restoring windows.
     Saved persistent state is lost, except for Untitled documents.

 -W  Causes open to wait until the applications it opens (or that were
     already open) have exited.  Use with the -n flag to allow open to
     function as an appropriate app for the $EDITOR environment variable.

 -R  Reveals the file(s) in the Finder instead of opening them.

 -n  Open a new instance of the application(s) even if one is already run-
     ning.

 -g  Do not bring the application to the foreground.

 -j  Launches the app hidden.

 -h  Searches header locations for a header whose name matches the given
     string and then opens it.  Pass a full header name (such as NSView.h)
     for increased performance.

 -s  For -h, partial or full SDK name to use; if supplied, only SDKs whose
     names contain the argument value are searched. Otherwise the highest
     versioned SDK in each platform is used.

 --args
     All remaining arguments are passed to the opened application in the
     argv parameter to main().  These arguments are not opened or inter-
     preted by the open tool.

答案3

解决方案是指定应用程序的绝对路径,而不是相对于当前目录的路径。

例如,
open /home/matt/MyApp.app

相关内容