|
|
 |
 |
 |
 |
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.
|
 |
 |
 |
 |
|