Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It sounds simple enough, but I'm having a hell of a time getting it to work. Apache expects the first line of my script to say #!<path_to_cmd_shell> And I don't want to use perl or anything else, I want to use c:\windows\system32\cmd.exe But no go.

When I run the rest of the cmd file from the cmd prompt, it works as expected.

I even have a test cgi that does this:

@echo off
echo Content-Type: text/html
echo ^<html^>^<head^>^</head^>^<body^>hi from stu the cgi ^</body^>^</html^>

and that works.

But when I change the script to run another exe (whose output would be the cgi response) I get all sorts of premature end of script headers.

I'm guessing that it has something to do with the output of the exe not piping back through the shell's output.

Any idea how to make this go?

share|improve this question
up vote 1 down vote accepted

I think your guess is correct. The exe file probably writes to the screen rather than stdout.

share|improve this answer

Forgive me for saying this if I'm wrong, but does Apache know how to execute a CMD file? In essence, I would expect you would have to give the script to apache in a manner it can understand. Perhaps you'd have more luck attempting to have a perl script execute the CMD and stream the output that way instead of attempting to directly execute the CMD script.

share|improve this answer
The first thing I tried was the @echo off in the first line, that seemed to tip apache off to something, because when I take that out, it just dumps the file contents to the browser. The other thing I tried was to put #!c:\windows\system32\cmd.exe as the first line so it would use that as the shell, and it did run that, but the stdout part doesn't work. – Stu Sep 4 '09 at 17:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.