[comp.unix.programmer] Help needed in interprocess communication problem...

ananth@eng.umd.edu (Sekhar C. Ananthakrishnan) (10/12/90)

Hi Netters,
	I have a problem with a piece of code I am trying to write and I was 
not able to get any ideas from  books.  So, I am posting it hoping that 
someone could help me.

	I have a "client" program which has a piece of code
similar to the following.....

		.
		.

	printf("Enter value for X");
	scanf("%d",&X);
	printf("Enter value for Y");
	scanf("%d",&Y);
	printf("The final value is %d\n", X+Y);

		.
		.


	I want to write another program say "handler", which forks client as a
child process, read the printf statements and supply values for the 
scanf statements using "read" and "write".  I do not want to change the
printf and scanf statements in the client to  "read" and "write".  How
do I synchronize the exchange between the shell and the client?
I want the handler program to do the following.


	read(0, buff, 256);
	/* at this point buff should contain "Enter value for X". */
	/* parse "Enter value for X" and give a value for X*/
	write(1,reply,strlen(reply)); /* where reply is a buffer containing
					value for X)*/
	read(0,buff,256)


and so on.  Could somebody tell me how it could be done? If there is an
easy solution, I would appreciate if somebody can E-mail me on how it
could be done.  Thanks in advance.

shyam 
ananth@mordor.eng.umd.edu