当输出重定向到 NSPipe 对象时,应用程序的行为是否有所不同?

发布于 2024-09-16 04:34:36 字数 551 浏览 1 评论 0原文

我有一个使用套接字并读取/写入数据的应用程序。它使用Foundation框架结合CFNetworkstdio

问题是——当它从控制台(bash shell)启动时,它工作 100% 正常,没有任何问题。然而,当另一个应用程序通过 NSTask 调用它时,疯狂就开始了。整个应用程序变得疯狂,它只读取套接字一次,然后挂起(意味着完成后退出)。

该应用程序不依赖于环境变量或任何其他类似的东西。这也不是用户的问题。当它启动时,它会向服务器发送一个简单的请求,并打印响应并再次读取。这种情况会一直发生,直到收到终止数据包为止。

我真的很困惑,感觉框架内有一些东西让应用程序变得疯狂,只是为了惹恼程序员。

顺便说一句,我使用的是 Mac OS X Snow Leopard,并且该应用程序适用于同一平台。

编辑1:stdout重定向到NSPipe会导致它。但为什么 ?

I have an application which works with sockets and reads / writes data. It uses Foundation framework combined with CFNetwork and stdio.

Here is the issue - when it is launched from console (bash shell) it works 100% fine and there is nothing wrong with. However when it is invoked by another application via NSTask madness begins. The whole application goes insane and it only reads the socket once and then hangs up (it is meant to exit after it is done).

This application does not rely on environmental variables or any other things like that. It is not a user issue either. When it is launched it sends a simple request to the server and 'printf's the response and reads again. This happens untill a termination packet is recieved.

I am really confused, and it feels like there is something inside the framework which makes the app insane just to piss the programmer off.

By the way, I'm on Mac OS X Snow Leopard and the application is for the same platform.

EDIT 1 : Redirecting stdout to an NSPipe causes it. But why ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静水深流 2024-09-23 04:34:36

libc 以不同的方式对待连接到(伪)终端的管道/文件和控制台。特别是默认的缓冲策略是不同的。请参阅此 Stack Overflow 问答中的广泛讨论。

因此,完全可以想象,连接到(伪)终端时可以运行的程序将无法使用管道运行。如果您需要更具体的建议,您需要发布代码(至少是框架)。

libc treats a pipe/file and a console connected to a (pseudo) terminal differently. In particular, the default buffering policy is different. See the extensive discussion in this Stack Overflow Q&A.

So, it's perfectly conceivable that a program which works when connected to a (pseudo) terminal won't work with a pipe. If you need more specific advice, you need to post (at least the skeleton of) your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文