Summary: | CGI output not captured | ||
---|---|---|---|
Product: | Apache httpd-2 | Reporter: | Stefan Krude <sk_np> |
Component: | mod_cgi | Assignee: | Apache HTTPD Bugs Mailing List <bugs> |
Status: | REOPENED --- | ||
Severity: | blocker | CC: | szg0000 |
Priority: | P2 | ||
Version: | 2.0.54 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows 2000 |
Description
Stefan Krude
2005-09-19 15:58:41 UTC
Please ask in a user support forum, if you have difficulty with the numerous examples of CGI scripts that capture the output of external programs. Sorry, I *asked* in users@httpd.apache.org but got no answer. And I have extensively googled - without result. What 'numerous examples of CGI scripts that capture the output of external programs' do you refer to? I don't think my example CGI script is wrong (it runs with IIS which I want to replace by Apache) and I don't see any mod_cgi directive that could be related to my problem. I didn't see that. Maybe if you said windows I just assumed it lay outside my expertise and I had nothing to say. You just capture the output from your child command, and print it back to stdout. So in *X your script could be something like: echo Content-type: text/plain echo echo pinging 192.168.0.160 /path/to/ping.exe 192.168.0.160 | while read line do echo $line done echo done Yes, this is what in *X will work, but in *X the problem doesn't exist, script output and output from progs called by the script is captured properly. Unfortunately Windows' cmd.exe doesn't know 'while' and 'read' and this would be an odd workaround anyway. I think if capturing from programs invoced by a script doesn't work with Windows, it must be a bug. (In reply to comment #4) > Yes, this is what in *X will work, but in *X the problem doesn't exist, script > output and output from progs called by the script is captured properly. > Unfortunately Windows' cmd.exe doesn't know 'while' and 'read' and this would be > an odd workaround anyway. > I think if capturing from programs invoced by a script doesn't work with > Windows, it must be a bug. > The bug is actually not an apache bug. Under windows a command script will not echo the output of any program it calls if @echo off is called. I suggest changing the script to: @echo off echo Content-type: text/plain echo. echo pinging 192.168.0.160 @echo on ping.exe 192.168.0.160 @echo off echo done and leave it there. If that doesn't work, reopen this bug. Of course that doesn't help. @echo off switches off the echoing of the command line, not the output of any program the script is calling. And as I said before: My scripts (that script with ping.exe is only a test script) are running well with Microsoft IIS, but I want to migrate to Apache and would expect that the scripts will work as well as with IIS (if not better ;-). I would suspect that PATH isn't set as expected. May that be? what does echo %PATH% put out? Is there anything in the error log that ping.exe is not found? (Can't test myself right now, sorry). No, the ping is executed, pls. look at my first posting:
> The host is pinged, thus the ping.exe is executed (I can see the ICMP packets
> with Ethereal, but the output of the ping program does not appear in the browser
> window (only the text 'pinging 192.168.2.160' and 'done').
The problem is *NOT* that the .exe isn't called but that it's output isn't
caputered and sent to the web client. The output of cmd.exe (the scripting host)
*IS* captured but the output of all of it's child processes is not.
oh well. Anyway; perhaps I've missed that also - there's still the question if there's anything in the error log. (In reply to comment #8) > No, the ping is executed, pls. look at my first posting: > > The host is pinged, thus the ping.exe is executed (I can see the ICMP packets > > with Ethereal, but the output of the ping program does not appear in the browser > > window (only the text 'pinging 192.168.2.160' and 'done'). > > The problem is *NOT* that the .exe isn't called but that it's output isn't > caputered and sent to the web client. The output of cmd.exe (the scripting host) > *IS* captured but the output of all of it's child processes is not. Sorry, I hastily threew that together earlier without thinking and I can see your problem. It appears that ping opens in a NEW command session rather than the Apache cmd session and therefore does not behave as expected. In other words, take this up with M$. This is a bug reporting forum, not a user support forum. Your problem is that on win32, ping never terminates unless you tell it to. Fix your script to perform it's action and -terminate- and perhaps you will have a working CGI. Bill Sorry, but that's rubbish. Of course ping.exe will terminate, but ping.exe is not the matter, it was just an example. Take for another example any hello world program. It's output will not be seen by the client if this program is called by cmd.exe running as an Apache CGI. Can anybody understand the problem? Isn't it a bug if the output of an scripted CGI never reaches the user? Isn't it a bug if the same script runs well with Microsoft IIS? Isn't it a bug if (nearly) the same script runs well with Apache/Unix? Please change your script to invoke ping.exe -n 4 192.168.0.160 and I think your problem will be solved (just tested locally). Yep, this still is an Issue on Windows XP with Apache 2.2.3. I am Not a Windows Guy, so this took me about a week to figure out. Some additional observations: 1) Internal cmd.exe commands (e.g. "echo", "dir") work fine 2) Re-directing the output of an external program (such as "ping.exe" or "netstat.exe") to a file yields a 0-length file. 3) If you set the "Allow service to interact with desktop" checkbox in "Administrative Tools->Services->Apache->properties->Log On", you can see the stdout from your commands in a desktop window which closes when the command completes. Also NB that running the script from a command line yields the expected results. The only work-around I could find was to drop back to apache 1.3.34, which works correctly. See also http://archive.apache.org/gnats/4898 |