Version 25 of Answered Questions On: Interprocess Communication

Updated 2005-12-19 01:04:33

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?
  • Calling COMMAND.COM/cmd.exe With Exec (Or WinUtils::Shell/Launch) Under DOS/Windows
  • Problems Running Exe/Com Files - Using Exec - In Windows

SEE ALSO:

  • ...

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]

 xx: bgexec from blt allows the redirection of stdout and stderr to tcl-variables

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] ;# :-)

Calling COMMAND.COM/cmd.exe With Exec (Or WinUtils::Shell/Launch) Under DOS/Windows

04/Aug/2003

when I am using below systax executing in tcl/tk, then I am getting error. Syntax is

set dirinfo exec command.com/c dir

Error I am getting, when I am executing this is

'invalid command name "command.com/c"'

How can I execute this? Could you please suggest me.

lv does DOS bat magic help?

RS Put a space between the filename command.com and the switch /c. DOS shells can do without the space, but Tcl requires whitespace between words.


Problems Running Exe/Com Files - Using Exec - In Windows

30/July/2003

I am facing some problems in tcl/tk windows version I am using tcl/tk 8.4.4.0 version on win 98. When I am using "exec" then I am getting errors. Example: set msg exec c:\cssplit.exe; where cssplit is "C" program and cssplit.exe executable file, when executing this, it's giving error "child process exited abnormally while executing exec cssplit". when I am executing batch files then it's givng couldn't execute test-spec.bat no such file or directory, but file is existing, not only this what ever I give with "exec" command all are getting errors. Could you please suggest me to execute this command.

lv I suspect that the problem here is that cssplit is either producing output on stderr or returning a non-zero return code. See catch for a way to account for these two alternatives. Note that it is easier to answer a question when you show us exactly what you type and what the output in return is, than when someone tries to summarize; in cases of errors, more information is likely to be beneficial...

Peter Newman 29 October 2004: Exec under Windows is usually way too complicated and confusing. It does heaps of things (like trying to capture the called processes stdout and stderr), which 99% of the time aren't necessary. A MUCH simpler alternative are the winutils ::shell and ::launch commands. Just feed them the filespec and any parameters, and they'll run the file - much as if you'd clicked on it from Windows Explorer, or called it from the command prompt. Feed it a .html file for example, and it'll automatically launch your default web browser. Another nice touch is that it accepts/requires filespecs in standard Tcl format (with forward slashes). So you don't have to bother converting them. Forget exec (and hours of grief); just use winutils.


Category Discussion - Category Interprocess Communication