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. :)

+2


source to share


3 answers


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.

+3


source


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.

+1


source


Does the script print headers when run from the terminal? If so, perhaps using -[NSTask setStandard*:]

(perhaps using NSPipe) will help capture the output. If not, it is possible that the web server is injecting headers when it is processing the CGI.

0


source







All Articles