NSTask returns HTTP headers
I am running /usr/bin/perl
or /usr/bin/php
via NSTask and want to get the HTTP headers of the program. I formatted the environment correctly (Perl requires env vars to start with a prefix HTTP_
), but none of the tasks return anything other than the original. I've gone through the NSTask documentation and man pages for php and perl and haven't seen any way to force HTTP headers to be output.
Any ideas?
EDIT . I realize this is an ancient question, but I just opened it and realized I have to report back. The problem was that I should have been using php-cli
, not php
. I had to download and compile php-cli
from source to get it working as I expected. However, once I did that, it worked like a charm. :)
source to share
You may need to prefix your output with an HTTP header that you generated based on the original output from your perl or php script.
For example, you know that the original output from a php script will be of type content: text / html, and you can get the length from the output itself. At least I think that's what I did while implementing a similar solution.
source to share
You cannot view or modify the environment of another process. The exception is that you can change the environment of a child process, but only when you create that process. This way you can set up the starting environment of your perl or php subprocess, but you cannot read which environment it was in later on, and you certainly cannot see what environment it had when it exited.
You need to force a Perl or PHP script to output your environment in some format and read that into your Cocoa process via a pipe.
source to share