Subprocess output to DOS script package not showing up in Apache

I am running Apache 2.2 (running through the console) in Vista. I have a simple batch of script in cgi-bin. Unfortunately, Apache doesn't seem to be serving content created by subprocesses.

For example, given the following script:

@echo off
echo Content-Type: text/html
echo.
echo Visible in browser
cmd /c echo Hidden from browser
echo End of script

All three lines of text will appear on the console if they are executed directly from the command line. However, the middle line ("Hidden from the browser") will not appear if running with Apache.

This script is just illustrative - I actually use a batch file to run several separate console applications (not cmd.exe)

What am I doing wrong?

+3
source share
4 answers

, : Java Java script

FWIW, C:\wamp\bin\apache\apache2.2.22\cgi-bin\testbat.bat echo , -:

@echo off
  rem  This works in Wampserver Apache cgi-bin...
  rem     http://localhost/cgi-bin/testbat.bat
echo Content-Type: text/html
echo.
echo ^<html^>^<head^>^</head^>^<body^>
echo ^<H1^>Hello world!!!^</H1^>
echo ^<PRE^>
FOR /F "usebackq delims==" %%i IN (`dir`) do echo %%i
echo ^</PRE^>
FOR /F "usebackq delims==" %%i IN (`cmd /c echo NOT hidden!`) do echo %%i
echo ^</body^>^</html^>
0

, cmd CreateProcess() DETACHED_PROCESS, Apache ap_cgi_build_command() apr_proc_create() ( Apache 2.2.25).

- cmd . (, WScript.CreateObject("WScript.Shell").Run() ), cmd .

: CreateObject(DETACHED_PROCESS) / (STARTF_USESTDHANDLES) , .

, , , WSH . httpd .

0

, , apache cgi-bin? , Apache cgi-bin ... ... , ... , Apache , , ssl ( )... Apache... httpd.conf

<LoadModule ssl_module modules / mod_ssl.so>
....
<if mod_ssl>
....
</if>

This explains why you cannot run the batch file as a cgi-bin script ...

-1
source

Perhaps you need to redirect the output to your STDOUT. I have not tried this on a windows machine, but you can try

cmd /c echo Hidden from browser >&1

or redirect it to a temp file and call it typein the file.

-1
source

Source: https://habr.com/ru/post/1730709/


All Articles