子过程中DOS批处理脚本在Apache中不可见的输出 [英] Output of sub-processes in DOS batch script not visible in Apache

查看:114
本文介绍了子过程中DOS批处理脚本在Apache中不可见的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行在Vista上的Apache 2.2(通过控制台启动)。我在cgi-bin目录简单的批处理脚本。不幸的是,阿帕奇似乎并不满足由子流程产生的任何内容。

I'm running Apache 2.2 (launched via console) on Vista. I have simple batch script in cgi-bin. Unfortunately, Apache does not seem to serve any content generated by sub-processes.

例如,考虑下面的脚本:

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

所有三行文字,如果直接从命令提示符下执行会出现在控制台中。但是,如果脚本来自Apache推出的中间线(从浏览器中隐藏)将不会出现。

All three lines of text will appear in the console if executed directly from a command prompt. However the middle line ("Hidden from browser") will not appear if the script is launched from Apache.

本脚本只是说明 - 我实际使用批处理文件来启动一批单独的控制台基于应用程序(不cmd.exe的)

This script is just illustrative -- I'm actually using the batch file to launch a number of separate console based applications (not cmd.exe)

我在做什么错了?

推荐答案

还有更多的细节不谈,这种行为发生在 CMD 通过的CreateProcess调用() DETACHED_PROCESS ,这是阿帕奇确实在 ap_cgi_build_command() apr_proc_create()(参考2.2.25 Apache的源$ C ​​$ C)。

Many more details aside, this behavior happens when cmd is invoked via CreateProcess() with DETACHED_PROCESS, which is what Apache does in ap_cgi_build_command() through apr_proc_create() (reference to Apache 2.2.25 source code).

由于某些原因,从 CMD 的子进程的的衍生分离。这也发生在其他情况下(例如,调用 WScript.CreateObject(WScript.Shell)。运行()在相同的情况下),这可能会或可能不会涉及 CMD 的背景。

For some reason, the child processes from cmd are also spawned detached. This also happens in other situations (e.g., invoking WScript.CreateObject("WScript.Shell").Run() in the same context) which might or might not involve cmd in the background.

无关的教训:如果的CreateObject(DETACHED_PROCESS)和I / O重定向( STARTF_USESTDHANDLES )混合在一起,结果可能是惊人的。

Unrelated lesson learned: if CreateObject(DETACHED_PROCESS) and I/O redirection (STARTF_USESTDHANDLES) are mixed together, results might be surprising.

据我所知,没有比避免批次,WSH等其他解决方案。在的httpd 球队可能会考虑这在未来一个解决方法。

As far as I know, there is no solution other than avoiding batch, WSH and others. The httpd team might look into this for a workaround in the future.

这篇关于子过程中DOS批处理脚本在Apache中不可见的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆