Playing with Pipes, Send and DDE

RJM: Below, a script is given which allows quick evaluation of basic pipe, comm send and dde operations. Not only shall the script serve quick evaluation, but also helps getting used with these topics. Interactive testing suggestions with (windows) wish are included.

For evaluation with unix targets, dde operations must be deleted from the script and a built in send can be utilized.

 # Playing process communication under Windows
 console show

 # open pipe with wish app
 set fid [open |wish r+]

 # prepare for comm send package
 package require comm
 # here prepare comm send on the other (piped) process
 puts $fid {package require comm};   flush $fid
 puts $fid {puts [comm::comm self]}; flush $fid
 # get the comm ID of the other process
 gets $fid cid; puts $cid

 # now communication is possible with comm send
 namespace import comm::comm*

 comm send $cid package require dde
 comm send $cid dde servername $cid

 # establish dde connection
 package require dde
 comm send $cid package require dde
 # just name the target dde the same as the comm id
 comm send $cid dde servername $cid

 ############# example for target process #############
 comm send $cid button .b -text ---
 dde eval $cid pack .b       ;# alternative to comm send
 # create a test proc that executes a wait time
 comm send $cid {proc wait ms {.b config -text $ms; update; after $ms; .b config -text OK}}

 # try several "wait" invocations in the wish console by hand:
 comm send        $cid wait 1000
 comm send -async $cid wait 1000

 dde  eval        $cid wait 1000
 dde  eval -async $cid wait 1000

 puts $fid {wait 1000}; flush $fid

The 5 variations given here as to execute them individually show how the script interacts with a remotely executed command.

As a general note it must be stated that send and dde eval normally wait until remote command execution is finished and in both cases the result is returned. So these methods really behave as remote execution. Remote execution via a pipe does naturally not return the result.

See also Transport independent send.


Category Example - Category Interprocess Communication