Mac OS X 应用程序/服务和标准输入?
我正在调试我正在开发的服务,它基本上会打开我的 .app 并将其传递一些数据到标准输入。但似乎不可能做到这样的事情:
open -a myapp.app < foo_in.txt
是否有可能将东西传递给 .app 的标准输入?
编辑: 抱歉,我应该把这个发布在 SO 上并且更清楚。我想做的是,我有一个用 Python + py2app 制作的应用程序。我希望能够在用户删除文件时处理这两个问题,并将其用作服务。第一种情况不是问题,因为 py2app 有 argv_emulation。我只是检查第一个参数是否是路径。
但是从标准输入读取根本不起作用,无论我是按照上面的示例还是通过管道读取它,它都不会读取任何数据。如果我将 stdin 数据传递给实际的 python 主脚本,它就可以工作。所以我重新表述我的问题,是否可以使用 py2app 包从 stdin 读取?
I'm debugging a service I'm developing, which basically will open my .app and pass it some data to stdin. But it doesn't seem like it's possible to something like:
open -a myapp.app < foo_in.txt
Is it possible to pass stuff to an .app's stdin at all?
Edit:
Sorry, I should have posted this on SO and been more clear. What I'm trying to do is that I have an app made in Python + py2app. I want to be able to handle both when a user drops a file, and use it as a service. The first case isn't a problem since py2app has argv_emulation
. I just check if the first argument is a path.
But reading from stdin doesn't work at all, it doesn't read any data regardless if I do as the example above or pipe it. If I pass stdin data to the actual python main script, it works. So I rephrase my question, is it possible to read from stdin with a py2app bundle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将其用作服务是什么意思?
您显示的示例不起作用,open 命令调用 LaunchServices 来启动应用程序,并且 LaunchServices API 中没有地方可以传递 stdin 数据或与应用程序类似的数据。
如果您的意思是向 OS X 服务菜单添加一个项目,您应该查看 开发人员的介绍性文档。
What do you mean with using it as a service?
The example you show won't work, the open command calls LaunchServices to launch the application, and there is no place in the LaunchServices API to pass stdin data or similar to the application.
If you mean adding an item to the OS X Services Menu, you should look at the introductory documentation for developers.
好吧,
将在您的 myapp.app 应用程序中打开 foo_in.txt。您需要应用程序的完整路径,无论是应用程序、bin 还是其他位置......
这取决于您的应用程序的用途。这可能更合适:
它将读取 foo_in.txt 的内容(使用 cat)并将它们传递到 stdin(使用管道),因此您只需按照命令/应用程序执行即可。
Well,
will open foo_in.txt in your myapp.app application. You need the full path of the application, be it Applications, bin, or wherever it is...
It depends on what your application does. This may be more appropriate:
That will read the contents of foo_in.txt (with cat) and pass them to stdin (with the pipe), so then you just follow that with your command / application.
要以 root 身份启动 Finder,不使用:
上面以 root 身份运行
open
,但仍然open
以普通用户身份运行 Finder。相反,人们会 使用:因此,接下来,也许(我真的只是猜测)需要:
To start Finder as root, one would not use:
The above runs
open
as root, but stillopen
runs Finder as the normal user. Instead, one would use:So, following that, maybe (I am really just guessing) one needs:
几乎可以肯定,您应该通过 Mach 端口或分布式对象或操作系统为您提供的几乎任何其他应用程序间通信方法来执行此操作。
You should almost certainly be doing this through Mach ports or Distributed Objects or pretty much any other method of interapplication communication the OS makes available to you.
open
创建一个全新的进程。因此,不要使用它从终端将内容重定向到应用程序。您可以尝试
已经提到的
cat Foo.txt | ./Foo.app/Contents/MacOS/Foo
很大程度上取决于您是否将 Foo 设置为 execurtbale 并且它在您的路径中。在您的情况下,我会检查 .app 包中的 Ressources 文件夹,该文件夹可能包含另一个二进制文件。*.app 包是一个目录。它无法处理命令行参数。
open
creates an entirely new process. Therefore do not use it to redirect stuff into an application from Terminal.You could try
Already mentioned
cat Foo.txt | ./Foo.app/Contents/MacOS/Foo
very much depending on whether you set Foo as execurtbale and it's in your path. In your case I'd check the .app package for a Ressources folder, that may contain another binary.A *.app Package is a directory. It cannot handle commandline arguments.