[comp.windows.x.motif] XtAddInput with pipes and fork and execlp

lau@desci.wharton.upenn.edu (Yan K. Lau) (01/24/91)

I'm writing a user-interface front-end to several programs.  These programs
asks a few questions and then prints output to the screen.  The programs
that I call can be run separately.  The interface is there to make it easier
to set the parameters.  

I've been following the Young book and have created pipes between my
interface program and a csh to which I send the commands to run these
programs.  These programs are called one after another.  Basically I
send the program name as stdin to the csh, anticipate the questions and
send the correct responses.

I don't know exactly how it works but it does.  The output is passed back
and displayed in a XmScrolledText with the stdin/stdout redirection and
a XtAddInput.

My problem is that I don't know when a program that I call is finished.
For instance, I put up a WorkingDialog on the screen just before I call
a program.  (An aside: If I don't ask the csh to sleep for a bit before
running the program, then the WorkingDialog doesn't get displayed
until after the program is done.  How do I correct this?) I need to know
when to remove the WorkingDialog box when the program is done.  How do I
do this?

Is there a better way to design the entire interaction between my interface
and the other programs?  I know that this is not entirely a Motif question
but I hope someone else has tackled this problem and have some answers and
suggestions.  Sorry for being so long-winded.


Yan.
-- 
   )~  Yan K. Lau    lau@kings.wharton.upenn.edu      The Wharton School
 ~/~   -Sheenaphile-          128.91.11.233       University of Pennsylvania
 /\    God/Goddess/All that is -- the source of love, light and inspiration!

geoff@Veritas.COM (Geoffrey Leach) (01/24/91)

From article <36193@netnews.upenn.edu>, by lau@desci.wharton.upenn.edu (Yan K. Lau):
> I'm writing a user-interface front-end to several programs.  These programs
> asks a few questions and then prints output to the screen.  The programs
> that I call can be run separately.  The interface is there to make it easier
> to set the parameters.  
> 
> I've been following the Young book and have created pipes between my
> interface program and a csh to which I send the commands to run these
> programs.  These programs are called one after another.  Basically I
> send the program name as stdin to the csh, anticipate the questions and
> send the correct responses.
> 
> I don't know exactly how it works but it does.  The output is passed back
> and displayed in a XmScrolledText with the stdin/stdout redirection and
> a XtAddInput.
> 
> My problem is that I don't know when a program that I call is finished.
> For instance, I put up a WorkingDialog on the screen just before I call
> a program.  (An aside: If I don't ask the csh to sleep for a bit before
> running the program, then the WorkingDialog doesn't get displayed
> until after the program is done.  How do I correct this?) I need to know
> when to remove the WorkingDialog box when the program is done.  How do I
> do this?

It's simple, tho bizzare.  Instead of forking and execing your command,
you fork and fork again.  (This is not just forking around!)  The child
of the first fork waits for the child of the second (your command) to
complete, then sends a message that the second child is to stdout, which
is then procedded by your routine that is doing the AddInput.

Have fun.

Geoff Leach