Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
using "interact" for inter process communication

Posted by Ima (Ima), 19 August 2005
I'm pretty new to tcl and definitely to expect.  The program I'm writing has two major pieces:

1. an action loop that runs long actions off of a queue

2. a command console that provides a prompt and takes user input to feed custom commands into the action loop when it's ready (i.e. it checks for the presence of special user entered commands at the beginning of each loop).

I fork 2 as a child of 1, and I thought I could use interact to send messages from 2 to 1, but it doesn't seem to be working.

This was what I created to test it out:

set parent_pid [pid]
set child_pid [fork]
     
     
     if {$child_pid} {
       # this is the parent
       
       #use interact to set input from the child and output to both parent and user
       interact -input $child_pid -output "$parent_pid $user_spawn_id"
       
       puts "parent: still sending output to the screen, but getting my input from $child_pid"
       
       #emulate being in another loop for a while
       sleep 30
       
       expect "hi"
       puts "I received <$expect_out(buffer)>"
       } else {
       #this is the child
       interact -input $child_pid -output "$parent_pid $user_spawn_id"
       sleep 5
       puts "child: sending hi to $parent_pid"

       send "hi"
       sleep 20 }
       
       }

I guess I have two big problems:

getting interact to let me "send" messages from the child process to the parent process. is there an easier way to do this?

receiving the message from the child even when the parent is busy running another procedure.


is there a simpler way for specific input from the user to set flags in the action loop so the next time it iterates it can take a different action?

Thank you!

Posted by admin (Graham Ellis), 20 August 2005
I wonder if you need interact at all.  It might be a bit overcomplex.  

If you're using Tk, you can set up background tasks for yor main applications and then event handlers to add any newwly submitted jobs to the queue.  Even in straight Tcl, you can read (non-blocking) from STDIN so that you can periodically check for user input and carry on if there's none there:

Code:
fconfigure stdin -buffering none -blocking 0
while 1 {
       puts tara
       after 1000
       gets stdin stuff
       if {$stuff != ""} {
               puts "Adding $stuff to buffer"
               }
       }


May not be exactly what you were planning, but I see you wrote about two major pieces of code and using this approach might mean that the input one at least can be done as just a minor piece

Posted by Ima (Ima), 7 September 2005
Holy cow, this worked perfectly! Thank you so much!

I was able to totally eliminate spawning that extra process to check input since I can just check after every event to see if there are new valid commands buffered in STDIN.

Thanks again  



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho