Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

How to exec a process and get the output of the process in tcl?


How to exec a process and get the output of the process in tcl?
Like using pipe stream from the process in C (popen).
Really appreciate your help.
On May 9, 9:18 am, hjin <h@provisionnetworks.com> wrote:

> How to exec a process and get the output of the process in tcl?
> Like using pipe stream from the process in C (popen).
> Really appreciate your help.

If you just want to run a child process and get its standard output,
do this:

set Result [exec foo  < bar]

If foo is a program that reads from standard input and writes on
standard output, what it writes on stdout will be captured and
returned as the value of a successul exec.

If you want to check whether the command was successful, you need to
use catch, like this:

if {[catch {exec foo  < bar} Result] == 0} {
   ...do something...

} else {
   ...error...
}

The value of the command that is the first argument to catch is placed
in the variable that is the second argument to catch. In this case,
that will be the standard output of the daughter process.
On 9 Mai, 18:18, hjin <h@provisionnetworks.com> wrote:

> How to exec a process and get the output of the process in tcl?
> Like using pipe stream from the process in C (popen).

See http://www.tcl.tk/man/tcl/TclCmd/exec.htm
Example:

 set content [exec cat $filename | grep foo | sort -u]

or, with a bidirectional pipe: http://www.tcl.tk/man/tcl/TclCmd/open.htm

 set pipe [open |myserver w+]
 puts $pipe $question
 gets $pipe answer
 puts "The answer is: $answer"

In article <1178727499.672422.39@y5g2000hsa.googlegroups.com>,

hjin  <h@provisionnetworks.com> wrote:
>How to exec a process and get the output of the process in tcl?
>Like using pipe stream from the process in C (popen).
>Really appreciate your help.

  set things_to_sort \
  "b
  d
  a
  c"
  set result [exec sort << $things_to_sort]
  puts $result
Thank you very much!
In article <1178727499.672422.39@y5g2000hsa.googlegroups.com>,

hjin  <h@provisionnetworks.com> wrote:
>How to exec a process and get the output of the process in tcl?
>Like using pipe stream from the process in C (popen).
>Really appreciate your help.

  set command_sequence "
    open ftp.microsoft.com
    user anonymous does_not_matter
    dir
    quit"
  set result [exec ftp -i -n << $command_sequence]
  puts $result

I think I'm being clever for illustrating with a Tcl script
that works (almost) equally well under Windows and Unix.
There are *very* few effective alternatives to ftp in this
role--netstat, nslookup, and finger among them.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc