Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Using Tcl as a CGI lang with Apache and Cygwin

Posted by byteflex (ByteFlex), 8 December 2003
Hi 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 (ActiveTcl8.4.4.0-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
error_log file:

[Wed Dec 3 13:33:22 2003] [error] [client] 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
or directory

Is this a standard result of using Tcl under Cygwin?


Posted by admin (Graham Ellis), 8 December 2003
No, 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 2003
Thanks 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:

# \
exec /cygdrive/t/Tcl/bin/tclsh84.exe "$0" "$@"

puts "Content-type: text/html"
puts ""
puts "<html>"
puts "<head>"
puts "<title>Sample Page</title>"
puts "</head>"
puts "<body >"
puts "<h3>Sample Page</h3>This file was produced with cgi.tcl!<br>"
puts "</body>"
puts "</html>"

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 2003
It 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 2003
Thanks 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 2003
Something 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.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho