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

exec or open "|"?

13 views
Skip to first unread message

Zhang Weiwu

unread,
May 9, 2011, 10:12:34 AM5/9/11
to
Hello. This is my discovery so far, please correct me if I am wrong:

reasons against exec:

could not output error in real time, which is a vital requirement
for my case because stderr contained progress information.

reasons against pipe:

In case of pipe, open "|xxx | yyy |& cat" could offer TCL script
real time stderr output of the last command in the pipe, but it is
the stderr outupt of the first command that I am interested in.

Plus, I am not sure how to properly escape file names that I pass
to 'open "|"', as the file name may contain single-quote ("Mum's
Lunch.odt") and double-quote (Oliver "Ollo" Twist.txt), it seems
much easier for exec.


So it seems I cannot use neither. 3rd option is to write a shell script
that contains the pipe (open "|sh -c '$cmd'" is more likely cause
trouble with file names with quote). 4th option is to handle the pipe
with TCL (low efficiency). What would you do?

Thanks for advices in advance!

Gerald W. Lester

unread,
May 9, 2011, 10:34:43 AM5/9/11
to
On 5/9/11 9:12 AM, Zhang Weiwu wrote:
> Hello. This is my discovery so far, please correct me if I am wrong:
>
> reasons against exec:
>
> could not output error in real time, which is a vital requirement
> for my case because stderr contained progress information.
>
> reasons against pipe:
>
> In case of pipe, open "|xxx | yyy |& cat" could offer TCL script
> real time stderr output of the last command in the pipe, but it is
> the stderr outupt of the first command that I am interested in.
>
> Plus, I am not sure how to properly escape file names that I pass
> to 'open "|"', as the file name may contain single-quote ("Mum's
> Lunch.odt") and double-quote (Oliver "Ollo" Twist.txt), it seems
> much easier for exec.

Neither or a problem, just have the file names in variables and do:
set fd [open "|xxx $fn(1) $fn2" ...]


> So it seems I cannot use neither. 3rd option is to write a shell script that
> contains the pipe (open "|sh -c '$cmd'" is more likely cause trouble with
> file names with quote). 4th option is to handle the pipe with TCL (low
> efficiency). What would you do?

Reread the Endekalogue until I understand it.


--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+

Ralf Fassel

unread,
May 9, 2011, 10:48:41 AM5/9/11
to
* Zhang Weiwu <zhangwei...@realss.com>

| Plus, I am not sure how to properly escape file names that I pass
| to 'open "|"', as the file name may contain single-quote ("Mum's
| Lunch.odt") and double-quote (Oliver "Ollo" Twist.txt), it seems
| much easier for exec.

Create the command as a *list*

set arg1 "Mum's Lunch.odt"
set arg2 {Oliver "Ollo" Twist.txt}

set cmd [list cmd $arg1 $arg2 $arg3]
set fd [open "|$cmd" ... ]

'open' parses its first arg as a list in the case of a pipeline, so any
spaces etc are conserved if you use 'list' to construct it.

R'

Zhang Weiwu

unread,
May 9, 2011, 7:46:49 PM5/9/11
to
Thanks all for answering the first part of my question regarding to
escape quotes in file name. I think now I should bring up the second
question in more vivid form on its own. I'll send a separate post about it.

Thanks!

0 new messages