Windows:如何从简单的CGI python服务器运行shell脚本

时间:2016-08-14 11:25:11

标签: python shell cgi

我使用http.server

创建了一个python Srver
python -m http.server --cgi 8000

服务器正在运行,我可以在其上运行python脚本。我正在尝试使用类似的内容运行shell文件。 我想我并不是要使shell文件可执行。在Windows中查找类似 chmod + x filename.sh 的内容。

Ubuntu等效链接:https://askubuntu.com/questions/229589/how-to-make-a-file-e-g-a-sh-script-executable-so-it-can-be-ran-from-terminal

目前我收到此错误:

Content-type text/htmlException happened during processing of request from ('127.0.0.1', 1659)
Traceback (most recent call last):

File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\socketserver.py", line 313, in _handle_request_noblock
    self.process_request(request, client_address)


File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\socketserver.py", line 341, in process_request
    self.finish_request(request, client_address)

File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\socketserver.py", line 354, in finish_request
    self.RequestHandlerClass(request, client_address, self)

File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\socketserver.py", line 681, in __init__
    self.handle()

File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\http\server.py", line 422, in handle
    self.handle_one_request()

File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\http\server.py", line 410, in handle_one_request
    method()

File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\http\server.py", line 645, in do_GET
    f = self.send_head()

File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\http\server.py", line 953, in send_head
    return self.run_cgi()

File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\http\server.py", line 1161, in run_cgi
    env = env

File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)

File "C:\Users\ABC\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
    startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application
< h1 >Hello World< /h1 >

更新

Python文件的内容:

#!/usr/bin/env python
print("Content-type text/html")
print("")
print("< h1 > Hello World < / h1 >")`

输出(在浏览器屏幕上)

Hello World  

外壳文件内容

#!/bin/bash
echo "Content-type text/html"
echo ""
echo "< h1 >Hello World< /h1 >" `

输出: 上面提到的错误。

想要类似输出 Hello World。

0 个答案:

没有答案