Tom Turkey
Tom Turkey

Reputation: 11

tcl open pipe seems to misshandle spaces in parameters

I have this open:

set r [catch {open "|[concat $config(cmd,sh) [list $cmd 2>@1]]" r} fid]

where $config(cmd,sh) is cmd /c and I am trying to pass a file name (and possibly a command such as echo) in $cmd. If there is no space in the file name, i.e. :
cmd is echo /filename
all is well. With a space, i.e.:
cmd is echo "/file name" what appears to be passed is:
\"file name\".
When I try this on Linux, I get "file name" (no backslashes). I have tried replacing the spaces in the file name with "\ ", but then the target gets two file names, i.e. the space is used to break up the file name.

I am beginning to think I have found a bug in the Windows port of Tcl...

Upvotes: 0

Views: 427

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137567

Ugh, that looks convoluted! To pass this sort of thing into the pipe creation code, you need to use exactly the right recipe:

set r [catch {open |[list {*}$config(cmd,sh) $cmd 2>@1] r} fid]

That is, always use the form with |[list ...] when building pipes as the documentation says that is what the pipe opener looks for. (This is the only command like that in Tcl.) And of course, using the (8.5+) {*} syntax is much simpler in this case too, as it is more obviously doing the right thing.

Upvotes: 3

Related Questions