开发者

Get StandardErrorPath from within the process in OS X 10.6

开发者 https://www.devze.com 2022-12-30 10:35 出处:网络
Is there a way to get the standard error/output path from within the process? I tried NSTask\'s standardError but it returns NSFileHandle, and I need the path as string.

Is there a way to get the standard error/output path from within the process? I tried NSTask's standardError but it returns NSFileHandle, and I need the path as string. Thank you!

p.s. StandardErrorPath is set in a .plist used by launchd to start the process on system start. The process is a b开发者_JS百科undle, written in objective c.


No you can't. Well strictly speaking you can, using a lot of hackery with the OS, but you shouldn't. You shouldn't determine the path for the standard streams and open the path and write/read on it.

Standard input / output/ error are not something associated to files. They are intrinsically associated to file handles, which are not necessarily associated to a path on the file system. They are an intentional abstraction over the concept of paths, so that a program can always write to the standard input/output/error without caring about the actual paths. This way, the choice of the path is done on the side of the user of the program, not the program itself.

What launchd does when it sees StandardErrorPath is conceptually this:

  1. As part of the initialization procedure, it opens the path in StandardErrorPath, get the file descriptor.
  2. Launch the app, setting that file descriptor to the "standard error file descriptor" of the app.

The app, when it wants to write to the standard error, should just write to the standard error, not try to determine the file path for the standard error and write to it.

0

精彩评论

暂无评论...
验证码 换一张
取 消