简体   繁体   English

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

[英]Windows: How to run a shell script out of a simple CGI python server

I have made a python Srver using http.server 我已经使用http.server制作了一个python Srver

python -m http.server --cgi 8000

Server is running and i am able to run a python script on it. 服务器正在运行,我能够在其上运行python脚本。 I am trying to run shell file with similar content. 我正在尝试运行具有类似内容的shell文件 I think i am not bale to make the shell file executable. 我认为我不愿意使Shell文件可执行。 Lookign for soemthing like chmod +x filename.sh in windows. 在Windows中寻找类似chmod + x filename.sh的东西。

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

Currently i am getting this error: 目前,我收到此错误:

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 >

Updated 更新

Content of Python file: Python文件内容:

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

Output: (on browser screen) 输出:(在浏览器屏幕上)

Hello World  

Shell File Content Shell文件内容

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

Output: Above mentioned error. 输出:上述错误。

Want the similar output Hello World. 想要类似的输出Hello World。

In windows there are no bash-scripts. 在Windows中没有bash脚本。 You only have .bat-Files with very limited syntax. 您只有语法非常有限的.bat文件。 If you try to run your script as filename.sh windows tries to find a program associated with the extension .sh and fails. 如果您尝试以filename.sh身份运行脚本,则Windows会尝试找到与扩展名.sh关联的程序,但会失败。 You should rename your file to filename.bat . 您应该将文件重命名为filename.bat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM