Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Strange command line behavior

21 views
Skip to first unread message

Hai Vu

unread,
Dec 27, 2007, 10:19:26 PM12/27/07
to
Hello every one,
I hope you can help this newbie with the following simple problem. I
have this one-liner:

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

Arjen Markus

unread,
Dec 28, 2007, 2:42:07 AM12/28/07
to

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

Cameron Laird

unread,
Dec 28, 2007, 7:02:18 AM12/28/07
to
In article <4c08836e-84b4-46bd...@b40g2000prf.googlegroups.com>,

Arjen Markus <arjen....@wldelft.nl> wrote:
>On 28 dec, 04:19, Hai Vu <wuh...@gmail.com> wrote:
>> Hello every one,
>> I hope you can help this newbie with the following simple problem. I
>> have this one-liner:
>>
>> 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
.
.
.

>Oh, perhaps the association (*.tcl --> tclsh *.tcl) does not
>allow you to pass command-line arguments!
.
.
.
Bingo.

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.

Cameron Laird

unread,
Dec 28, 2007, 9:27:48 AM12/28/07
to

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" %*

Hai Vu

unread,
Dec 28, 2007, 6:20:25 PM12/28/07
to
Hello Cameron and others,
I would like to thank for pointing me to the right direction. I
finally was able to pinpoint the source of the problem by digging into
file association using regedt32.exe. First, to answer Cameron's
questions:

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.

Jean-Francois Larvoire

unread,
Jun 16, 2008, 12:37:20 PM6/16/08
to
Hello,

> 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>

0 new messages