ctcl

Introduction

ctcl is basically a tclkitsh or tclsh replacement for Windows. It is a console application with TWAPI bound in. Binary download from [L1 ]

The biggest difference from tclsh or tclkitsh is in its accepting scripts from the command line using standard Tcl syntax and some extensions that make interactive use convenient. It allows me to use Tcl as a common command line tool for systems administration, rummaging the disk, pipelining etc instead of keeping track of a hodge podge of standalone tools. Examples are given later.

Without any arguments, ctcl behaves (almost) like tclsh.

If the first argument is a script file, ctcl behaves (almost) like tclsh.

Otherwise, ctcl treats the entire line as a Tcl script. No magic, but very convenient under Windows.

ctcl is still work in progress. Commands and features are liable to drastic change. Suggestions that streamline interactive use are much appreciated.

R:\>ctcl glob *
ctcl-prerc.exe ctcl-runtime.exe ctcl.exe ctcl.vfs foo.txt x.tcl

Or, as a standard tclsh shell,

R:\>ctcl
...
ctcl> glob *
ctcl-prerc.exe ctcl-runtime.exe ctcl.exe ctcl.vfs foo.txt x.tcl
ctcl>

Ctcl by Example

tcl::mathop are autoimported

R:\>ctcl * 2 3
6
R:\>ctcl + {*}[collect [files -pattern *.tcl] eval {file size $_}]
427090

twapi commands are also autoimported.

R:\>ctcl get_process_ids -name notepad.exe
3328 1684

ctcl has its own built-in convenience commands.

R:\>ctcl toclip [read stdin]
This text will go into clipboard
^Z

Useful as a flexible Tcl based filter.

R:\>cat foo.txt | ctcl string toupper [read stdin]

The command line may have compound commands.

R:\>ctcl + {*}[collect [files -pattern *.tcl] eval {file size $_}]
427090

Command may also be continued across multiple lines.

R:\>ctcl foreach pid [get_process_ids -name notepad.exe] {
> puts "Killing PID $pid"
> end_process $pid
> }
Killing PID 2804
Killing PID 2352

or more succintly

R:\>ctcl leap [pids notepad] {end_process $_}

Some facilities for pretty printing are included. Dump process information...

R:\>ctcl pp [processes -name -virtualbytes]
   0 System Idle Process                     0
   4 System                            1929216
 180 svchost.exe                      37003264
 268 IntuitUpdateService.exe         145453056
 348 NitroPDFReaderDriverService.exe  26030080
 432 alg.exe                          33595392
 ...

...or network connections for port 80.

R:\>ctcl pp [get_tcp_connections -matchremoteport 80]
192.168.1.2 3464 209.85.153.100 80 estab     1344 0 firefox.exe C:\Program Files\Mozilla Firefox\firefox.exe
192.168.1.2 3463 209.85.231.100 80 estab     1344 0 firefox.exe C:\Program Files\Mozilla Firefox\firefox.exe
192.168.1.2 3446 209.85.153.132 80 time_wait    0 0
192.168.1.2 3447 209.85.153.132 80 time_wait    0 0

Command Reference

The vast bulk of commands are of course those from Tcl and TWAPI. However, ctcl adds a few convenience commands that are particularly useful in interactive use.

background

collect

every

files

fold

fromclip

funnel

hexdump

leap

leap?

license

lines

pids

pp

processes

toclip