by montgomme » Thu, 05 Feb 2004 23:10:10
I am now remembering TCL and I have came across with a problem when
doing something I used to do.
My purpose is to implement a console-like GUI to present in a listbox
outputs from another program written in c and allow to command orders
via an entry. All the communication between both programs will be via
pipeline
As a first approximation, I tried several easy examples and I get
stucked with these two programs (see below).
When executing tclprogram2.tcl I get Done1 and Done2 and nothing more:
i must end it with Ctrl-C. However, if I change Hello3 lines before
for loop, the program run smoothly (even without changing cprogram2),
but this is not what I need, as I must see what the cprogram writes
before giving an answer.
Any ideas of how solve it?
----------------------------------------------------------
tclprogram2.tcl:
----------------------------------------------------------
#!/bin/sh
# the next line restarts using wish \
exec wish8.1 "$0" "$@"
set ProgramPid [ open "| ./cprogram2" "r+" ]
set GrepResult [exec ps -ef | grep cprogram ]
puts stdout $GrepResult
puts $ProgramPid "Hello"
flush $ProgramPid
puts stdout "Done1"
puts $ProgramPid "Hello2"
flush $ProgramPid
puts stdout "Done2"
foreach i { 0 1 2 3 4 5 6 } {
set SalidaStatus [gets $ProgramPid Salida]
puts stdout "$Salida $SalidaStatus"
}
puts $ProgramPid "Hello3"
flush $ProgramPid
puts stdout "Done3"
set SalidaStatus [gets $ProgramPid Salida]
puts stdout "$Salida $SalidaStatus"
----------------------------------------------------------
cprogram2.c:
----------------------------------------------------------
#include <stdio.h>
#define MAX_NUMBER 5
#define DELAY 100000
int main (void)
{
int i, j;
char orden_tcl[100] = "prueba";
char orden_tcl2[100] = "prueba";
char orden_tcl3[100] = "prueba";
scanf("%s", orden_tcl);
scanf("%s", orden_tcl2);
printf("Tcl ha dicho: %s y %s\n", orden_tcl, orden_tcl2);
for (i= 0; i < MAX_NUMBER; i++)
{
printf ("%d\n",i);
}
printf ("Fin delay\n");
scanf("%s", orden_tcl3);
printf("Tcl ha dicho: %s \n", orden_tcl3);
}