使用由Web浏览器

时间:2016-07-14 06:14:54

标签: python c subprocess cgi exe

我正在运行一个带有python脚本的exe,它由Web浏览器调用。

Exe文件存储在服务器端。 Exe文件接受一个输入文件,并在输出中返回几个文本文件。运行exe的python脚本如下:

import subprocess
print ("Hello I am in python script")

args = "/path/import.exe /path/input_file.txt -terms".split()

popen = subprocess.Popen(args, stdout=subprocess.PIPE)

popen.wait()

output = popen.stdout.read()

当我单独执行python脚本时,它会按预期运行并在cgi-bin文件夹中输出几个文本文件。

但我想从我的网络浏览器运行这个exe文件,因此我将它放在我的xampp服务器上的cgi-bin文件夹中。

在我的网络浏览器上输入网址,如下所示: http://localhost/cgi-bin/script.py

脚本已执行但我无法看到exe文件的预期输出,如果在终端上单独执行,则无法正常工作。

我编辑了httpd.conf文件,允许在Web服务器上处理.py文件。 script.py文件有一个给系统上安装的python的路径。给出的路径是绝对路径。 exe文件的权限,script.py目前是chmod 777,用于测试目的。

我无法从python的子进程模块中捕获任何错误。我在模块中使用了stderr但它没有打印任何信息。

1 个答案:

答案 0 :(得分:0)

您可以将输出重定向到页面,在打印之前执行类似的操作。

sys.stdout.write("Content-Type: text/html\r\n\r\n")

也许这可以帮到你: Display the result on the webpage as soon as the data is available at server