Re: How can i let shell program within TCL show run log?



On Jun 18, 12:30 pm, Ahmad <ahmad.abdulgh...@xxxxxxxxx> wrote:
Hi Alex,

Thank you again.

Would you kindly explain the above example in a much easier way (i'm
quite newbie to Tcl unlike you expert!).

I don't understand batch of stuff:
- Is the ">@" operator part of Unix or Tcl syntax? What is it exactly
used in? What does advancing it with a number like 2>@ or a letter a>@
and so forth mean?

Look at the [exec] Tcl manpage for these strange <>@ beasts :-)
You'll find there that >@ means "redirect child's stdout to a Tcl
channel", and 2>@ the same for child's stderr.

- What happens when you execute: open "|cat" ??

Wow. New to unix too, right ?
As it turns out, 'cat' without arguments is just a "byte noria"
pumping its stdin to its stdout. So [open "|cat" r+] essentially gives
you a "free pipe": anything written on the write side of the channel
$pi can be read on the other side shortly thereafter. So when you say

set ff [open "|foo bar 2>@ $pi r]

you have the child's stdout to be pumped out of $ff, and its stderr to
be pumped out of $pi. OK ?

I can't understand either it or : open "|cmd args ... 2>@ $pi" . Does
the "..." mean specific thing? Would you please explain, again?

Sorry "cmd args ..." was my way of saying "your command and its
arguments" :-)

- Finally, i would really appreciat if you gave me an example that
could be directly ran to display a command output on a text widget (a
command like "cat" for a long file)

Beware that all the added complexity with the "free pipe" is needed
only if you want to distinguish what gets out of stdout from what gets
out of stderr. Not sure it is your case, you didn't say.

So here I'm giving the example in the simple case: no distinction.
Both stdout and stderr from the child mixed together:

We'll be using the unix command "vmstat" for this example, because it
outputs slowly and regularly:

Start wish and type:

text .t
pack .t
proc tolog ch {
if {[gets $ch line]<0} {close $ch;return}
.t insert end $line\n
}
set ff [open "|vmstat 1 2>@1" r]
fileevent $ff readable [list tolog $ff]

-Alex
.



Relevant Pages

  • Re: STDOUT and STDERR redirection fails for forked process
    ... Simply, fork a command using the OPEN instruction, ... redirect STDERR to STDOUT and capture the returncode of the executed ... and the returncode is not captured. ...
    (comp.lang.perl.misc)
  • Re: getting stdout and stderr for system calls on windows
    ... It doesn't separate stderr and stdout, but for what I want it, it's more than enough. ... #You can then access the output and the return value for the command. ... def initialize cmd ...
    (comp.lang.ruby)
  • Re: Copying silently.
    ... so as to ReDirect both StdIn & StdErr for a Command, ... to think that "I've done it" is fit for stdout, ... do it" is fit for stderr. ... for reports on both Failure & Success? ...
    (uk.people.silversurfers)
  • Re: Getting both PID and output from a command
    ... > I'm calling a command from within a python script and I need to be ... > able to both catch the output (stdout and stderr) from it and also ... > I've tried doing the following to grab stderr (I only need stderr, ... I wouldn't trust using a pipe. ...
    (comp.lang.python)
  • Re: open "|command", close, catch, errorCode == NONE
    ... As I said, I only need the whole text, whatever the command printed on either ... stdout or stderr - I don't need to check for differences. ... is done by Tcl, and will then grab everything, including early life. ...
    (comp.lang.tcl)