puts "argc = $argc"
and saved it to cmdline.tcl. If I invoke the program directly like
this:
cmdline.tcl one two three
then the result is:
argc = 0
If I invoke it as:
tclsh cmdline.tcl one two three
then the result is correct:
argc = 3
Is this a bug? How can I get around this bug to get the program
working correctly?
Here is my environment:
Tcl version: 8.4 (8.4.16) (ActiveState Tcl)
OS: Windows Vista
I always use argv and [llength $argv].
What happens if you change the code to:
puts "argc = [llength $argv] - $argv"
(Note: argv contains a list of all the command-line arguments)
Honestly, I was not aware of argc as a predefined variable ;)
Oh, perhaps the association (*.tcl --> tclsh *.tcl) does not
allow you to pass command-line arguments!
Regards,
Arjen
That is, in vernacular American, this last statement is correct.
I'll follow up later with a non-standard association for Tcl that
passes command-line arguments closer to the way one might expect.
Hmmm! I thought we'd documented these matters on one convenient
page--but I haven't been able to find it.
On reflection, the original report puzzles me. It sounds like an
unusual installation of ActiveState Tcl. Hai Vu, what are the
results when you request
assoc .tcl
ftype ActiveTclScript
at the DOS command prompt?
If all you want is to ensure that
cmdline.tcl one two three
works as you seem to expect, and your other reports are precise,
you might experiment with
ftype activetclscript=tclsh "%1" %*
C:\>assoc .tcl
File association not found for extension .tcl
C:\>ftype ActiveTclScript
File type 'ActiveTclScript' not found or no open command
associated with it.
Weird. Then my search in the registry took me to this point:
HKEY_CLASSES_ROOT\tcl_auto_file\shell\open\command
and the default value there is:
"C:\Tcl\bin\tclsh.exe" "%1"
Per Cameron's suggestion, I changed it to:
"C:\Tcl\bin\tclsh.exe" "%1" %*
and everything works beautifully. Again, thank you Cameron and others
for helping me fixing this problem.
> HKEY_CLASSES_ROOT\tcl_auto_file\shell\open\command
> and the default value there is:
> "C:\Tcl\bin\tclsh.exe" "%1"
> Per Cameron's suggestion, I changed it to:
> "C:\Tcl\bin\tclsh.exe" "%1" %*
> and everything works beautifully.
I had the same problem of command line arguments not being passed to my Tcl
scripts on my new Vista PC.
But the procedure above was not sufficient to fix it.
Actually on my system the configuration is slightly different:
* Tcl is installed in "C:\Program Files\Tcl\"
* There is no HKEY_CLASSES_ROOT\tcl_auto_file key, but there is a
HKEY_CLASSES_ROOT\ActiveTclScript key.
This key was initialised by ActiveState distribution setup to <<"C:\Program
Files\Tcl\bin\wish84.exe" "%1" %*>>, with the corect %* argument.
Yet, even after changing in to <<"C:\Program Files\Tcl\bin\tclsh.exe" "%1"
%*>> command line arguments were not passed to my tcl scripts.
C:\JFL\Temp>assoc .tcl
.tcl=ActiveTclScript
C:\JFL\Temp>ftype ActiveTclScript
ActiveTclScript="C:\Program Files\Tcl\bin\tclsh.exe" "%1" %*
C:\JFL\Temp>t.tcl one two
argv={}
C:\JFL\Temp>
After searching for other instances of tclsh.exe in the registry, I found
that there's another key that needs to be changed:
HKEY_CLASSES_ROOT\Applications\tclsh.exe\shell\open\command
contained <<"C:\Program Files\Tcl\bin\tclsh.exe" "%1">>
After changing it too to <<"C:\Program Files\Tcl\bin\tclsh.exe" "%1" %*>>
then the arguments make it through.
C:\JFL\Temp>t.tcl one two
argv={one two}
C:\JFL\Temp>