For Programmers: Free Programming Magazines  


Home > Archive > Tcl > December 2007 > Strange command line behavior









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Strange command line behavior
Hai Vu

2007-12-27, 10:14 pm

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

2007-12-28, 4:31 am

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 =3D $argc"
>
> and saved it to cmdline.tcl. If I invoke the program directly like
> this:
> =A0 =A0 cmdline.tcl one two three
> then the result is:
> =A0 =A0 argc =3D 0
>
> If I invoke it as:
> =A0 =A0 tclsh cmdline.tcl one two three
> then the result is correct:
> =A0 =A0 argc =3D 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 =3D [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

2007-12-28, 8:12 am

In article <4c08836e-84b4-46bd-9716-7e78281628ba@b40g2000prf.googlegroups.com>,
Arjen Markus <arjen.markus@wldelft.nl> wrote:[color=darkred]
>On 28 dec, 04:19, Hai Vu <wuh...@gmail.com> wrote:
Cameron Laird

2007-12-28, 7:17 pm

In article <a75f45-fac.ln1@lairds.us>, Cameron Laird <claird@lairds.us> wrote:
>In article <4c08836e-84b4-46bd-9716-7e78281628ba@b40g2000prf.googlegroups.com>,
>Arjen Markus <arjen.markus@wldelft.nl> wrote:
> .
> .
> .
> .
> .
> .
>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.


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

2007-12-28, 7:17 pm

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\op
en\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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com