Skip to content

Instantly share code, notes, and snippets.

@getify
Created June 3, 2010 13:38
Show Gist options
  • Save getify/423890 to your computer and use it in GitHub Desktop.
Save getify/423890 to your computer and use it in GitHub Desktop.
use Apache2::SubProcess();
$r = shift();
print "Content-type: text/html\n\n";
my($in, $out, $err) = $r->spawn_proc_prog("myprog");
while (<$out>) {
print $_; # works fine
}
use Apache2::SubProcess();
$r = shift();
print "Content-type: text/html\n\n";
my($in, $out, $err) = $r->spawn_proc_prog("myprog");
print $in "cool"; ### will cause the script to hang
while (<$out>) {
print $_;
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
int content_length = 100, current_size = 0;
char cread;
char* content = NULL;
do {
cread = fgetc(stdin);
if (cread && cread != EOF) {
if (content==NULL) content = (char*)malloc(content_length);
else if (current_size == content_length-2) {
content_length *= 2;
content = (char*)realloc(content,content_length);
}
if (content==NULL) {
return 1;
}
content[current_size++] = cread;
}
} while (!feof(stdin) && cread && cread != EOF);
content[current_size] = '\0';
printf("%s\n",content);
free(content);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment