views:

19

answers:

1

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 bundle, written in objective c.

+1  A: 

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.

Yuji
The point was to rename the log-file given as StandardError/OutputPath on process start. This way there will be separate files for the log - for example for each date. Anyway, obviously I should think for a workaround.Thank you for your answer.
stan0
I see. But then, why don't you just use `syslog` or `asl`? I prefer not to re-invent the wheel.
Yuji