tags:

views:

68

answers:

1

I'm trying to compose a .zip file in a CGI program and send that as the content response. I'm getting stuck in that whenever I spawn a program that prints to stdout, that somehow doesn't get accepted by Apache. It seems to be something to do with spawning a program that writes to stdout. The snippet below reproduces this problem. I always get the following error form Apache:

malformed header from script. Bad header=hello world  

print ("Content-Type: text/html");  
print ("");  
#print ("hello world");     <-----This works  
os.system("echo hello world");  <-----This doesn't work

It works fine if I just print the string from my CGI script. If I run it with either statement from the command line, there's no difference in behaviour. Is there something special I need to do to get the stdout from a spawned program out as my respone?

+1  A: 

Try sys.stdout.flush() before calling external programs.

Ignacio Vazquez-Abrams
That did the trick. Thanks!
Matthias Wandel