Version 14 of Answered Questions On: Interprocess Communication

Updated 2004-10-29 09:19:05

EDIT/RECENT CHANGES


NAVIGATION


TABLE OF CONTENTS (Interprocess Communication):

  • Does Tcl Support "SendKey" And "SendMessage" (For Controlling Other Windows Applications)?
  • Using Exec To Capture A Child Processes Stdout And Stderr
  • How Does One Tcl Interpreter Access Variables/Values In Another (Tcl Interpreter)?
  • How Do I Pass A Variable/Value To A Child Interpreter?

Does Tcl Support "SendKey" And "SendMessage" (For Controlling Other Windows Applications)?

22/09/2003

Does Tcl includes the ability to control other applications, e.g. notepad? Other programming languages provide commands like Sendkey (VB) or Sendmessage (VC). So I can executing notepad, putting text into textbox and saving that in a file. That's all possible because of controlling menuoptions by sending Windows-Messages ... It is possible in Tcl too? - RS: See tcom for COM support, but not sure whether Notepad understands that.. - JPT: You could also try cwind (http://mini.net/tcl/5019 ). I've used it once and it did the (simple) job I had to do.


Using Exec To Capture A Child Processes Stdout And Stderr

Sep 26 - 2003 I want to make a frontend to gcc in tcl.

    if {[catch {exec gcc -c $Compiler_Flags $Filename } Result]} {
      puts $Result
      exit 1
    }

I want to map gcc's output messages to stdout and stderr, while the command runs. I could direct it to a file, but we'll proberbly be running this frontend, several persons at the same time. - RS: Experiment with

 eval exec [list gcc ... > @stdout 2> @ stderr $Compiler_Flags [list $Filename]

How Does One Tcl Interpreter Access Variables/Values In Another (Tcl Interpreter)?

08/26/2003

INTERCOMMUNICATION

You start two wish-interpreters, wish1 and wish2. In wish1 you create a variable:

  % set x(val1) 0
  0

My question: How can I make x accessable for wish2? Thanks for all solutions or ideas! PB

FW: What OS are you using? Do you mean multiple executions of one interpreter, or a slave interpreter within one application? Are you developing cross-platform?

If you mean multiple applications, you're in luck by using Tcl, which is very strong for inter-application communication. Tk has a built-in send command, and the comm package provides similar functionality via sockets that works cross-platform.

It's even easier with slave interpreters - just look at the interp page to find out how to send commands to a slave interp.

PB: I'm using XP for this project and primarily I try to find an easy concept for an applications conversation and interp is my favorite now. Thank you...

FW: So does that mean you're using slave interpreters or separate applications?

PB: (curios?) I use slave interps althought separate applications would be better. therefore better because if master interp has a problem, slaves will have a problem too. sure, there are possibilities to catch and handle such cases, but that costs a lot of time and time is money. on the other side I have a problem to exchange common data using seperate applications because they run in different enviroments.

FW: Thanks for clarifying. Just use [interp eval] to run commands within the slaves. If and when you start using separate applications, I'd use the comm package (based on the venerable send) for inter-app communication.


How Do I Pass A Variable/Value To A Child Interpreter?

02/04/2004

Hi, does someone knows if I can access a variable in child-interp-context?

 proc change_dir { __dir } {
     interp create child
     interp eval child {cd $__dir}
     ...
 }

I know, in interp child $__dir does not exists. Is there a way to put a value from invoking interp into child-interp? Perhaps with interp alias? PB

RS: In your case it's even easier, just substitute the variable before calling interp eval:

 interp eval child [list cd $__dir] ;# :-)