Using Tcl as a CGI lang with Apache and Cygwin
Posted by byteflex (ByteFlex), 8 December 2003Hi All,
A bit specific this one, but here goes...
Has anyone come across a problem using Tcl for CGI scripts under Cygwin?
System details are:
- Windows XP
- Cygwin (CYGWIN_NT-5.1 1.5.5(0.94/3/2) 2003-09-20 16:31 i686)
- Apache 1.3.24-5
- ActiveTcl (ActiveTcl220.127.116.11-win32-ix86)
CGI works if I use bash shell scripts to deliver the HTML content, delivering
exactly the same content through a Tcl script does not.
Tcl script has same ownership and permissions and resides in same directory
as Bash script, both produce identical output when run from command line.
However, when capturing output of test scripts to file and comparing them
in a hex editor, it looks like the Tcl output has an CRLF at the end of each
line whereas the Bash output has just LF. I know from previous experience
that Apache doesn't tolerate DOS formatted files as Scripts, but the scripts
I am using are not DOS formatted - just the output from the Tcl script is.
The result is the same whether I use Mr. Libes "cgi.tcl" or use a plain Tcl
script of my own creation. Both result in the following messages in Apache
[Wed Dec 3 13:33:22 2003] [error] [client 18.104.22.168] Premature end
of script headers: /usr/local/apache/cgi-bin/tcltest.cgi
couldn't read file "/usr/local/apache/cgi-bin/tcltest.cgi": no such file
Is this a standard result of using Tcl under Cygwin?
Posted by admin (Graham Ellis), 8 December 2003No, I haven't come across that one ... BUT ... I might be able to guess at a work around
If your script uses puts commands to generate the headers, add in the -nonewline option and also add a \n onto the end of the header line ....
Just a thought; it may help ... and it shouldn't matter once you've passed the header back whether or not you send back LFs in the body of your reply!
Posted by byteflex (ByteFlex), 9 December 2003Thanks for your suggestion.
The Tcl distro shipped with Cygwin works ok. However, using ActiveTcl does not. The reason for using ActiveTcl is that I wanted to use a common distro in and out of Cygwin, with one instance of each package, db and all resource files I load.
Just tried this script...
Where originaltestscript.cgi contains:
And it works!
Permissions and ownerships are the same for boths files.
Why doesn't originaltestscript.cgi work directly, any ideas?
Posted by admin (Graham Ellis), 9 December 2003It looks to me like one distribution is generating new line characters correctly, and the other is genarating a extra character in the sequence. Did you try my suggestion out so see if it helps?
Posted by byteflex (ByteFlex), 10 December 2003Thanks Graham,
I did try what you suggested. This does work with Cygwin distro of Tcl, however it does not work with ActiveTcl running under Cygwin.
I had already created a script which behaved identically in both (i.e. by using puts -nonewline "...\n"), and checked the output in a Hex Editor to make sure.
However, only the standard Cygwin distro worked. Wierd, eh?
The thing that I find difficult to understand is from my previous posting. The fact that the errant script works (i.e. same characters being sent to Apache), but only when it is executed from within another script.
Posted by admin (Graham Ellis), 10 December 2003Something to do with DOS wrappers no doubt ... they're adding in the spurious extra character at the end of the ActiveState distribution and perhaps the extra character is being stripped out again by the shell. I'm wondeing if there's a "binmode" or equivalent in the Activestate Tcl ... such a mode is the standard way to avoid such problems with data being transformed in many systems/languages, rather like the Ascii/binary switch in Ftp.
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho