New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http/cgi: support Python etc non-executable scripts on Windows #18420
Comments
This works for me if I make sure test.py is executable:
Also, there were some strange whitespace characters in the file that were causing problems. Note that I am running on darwin and am not really sure how to fix this on Windows. |
You need to somehow make the program test.py runnable on Windows.
On Unix, you can add a shebang header and make the script executable.
I don't know how to achieve that on windows.
I don't think this is a Go bug. Please ask questions on other mediums,
see https://golang.org/wiki/Questions
|
@minux, but "runnable" on a file is a concept that doesn't exist on Windows. We should do whatever other popular CGI servers do. (Whatever that is.) Shebang support, perhaps? |
On windows, it's likely based on file suffix alone.
@alexbrainmain.
One simple solution is perhaps using "cmd /c start script.py arguments...",
but I don't know the implications.
|
For Windows, you should handle extension whether it will be runnable. https://github.com/mattn/go-cgiserver/blob/master/cgiserver.go BTW: s/alexbrainmain/alexbrainman/ |
There's a WINAPI called ShellExecute, equals to cmd /c script.py, but have no idea if it's applicable to use this here. Maybe will link to windows dll file. |
@bradfitz |
You just need to use a special shebang line for Python scripts
on Windows (and also save the script with suffix .bat):
@"c:\python27\python.exe" -x %~f0 & exit /b
I think this is also possible for Perl (it's probably easier for Perl,
because perl's syntax is not as strict as Python's, and I have to
resort to use -x to write a Python/bat polyglot.)
While Windows batch files are quite limiting compared to Unix
shell scripts, this is still possible.
|
Thank you, This works for me at least. |
You need to name the python script with .bat suffix to persuade
the system to execute it.
It's fundamentally a Python script embedded within a Batch
script.
|
code editor will not be useful for these script files, as many functions will not work, such as highlighting, autocompletion, etc. |
MS Windows has different approach than *nix systems for FileType and Application association. There can be multiple associations, and association can have multiple options (first in list being default). Or, we can query windows registry just once for every extensions to find registered launcher for the script, and cache it. Apache HTTPD perhaps looks into cgi file shebang for per/python. |
I guess AssocQueryString make unexpected behavior when the file is .docx or something which is not expected as CGI. |
What does CGI do on unix when file is .docx? Or .html or whatever? Alex |
Windows doesn't have executable-permission as same as UNIX's one. So we have to handle the file-suffix which can runnable with white-list. If it use AssocQueryString without white-list, the server may start Microsoft Word for the |
Could we just check the PE file's Console-vs-GUI type and not execute *.exe files if they're GUI exes? |
Yes we could do that. Alex |
I would suggest (at least as a workaround) to create a bat script
These proxy scripts can then be generated automatically for all scripts that should be made available via the CGI. I believe this is a rather common alternative to shebang on Windows. |
I think so. Over hack can be a trouble afterwards. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.7.4
What operating system and processor architecture are you using (
go env
)?set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=
set GORACE=
set GOROOT=D:\Go
set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
cgidemo.zip
Change to unziped directory, and execute
go run cgi.go
, then visit http://localhost:8000/cgi-bin/test.pyWhat did you expect to see?
Hello on my browser
What did you see instead?
The page hangs up
The text was updated successfully, but these errors were encountered: