[comp.lang.c] sending input to a child

mbp5756@sjfc.UUCP (Mike Berry) (03/07/89)

I was just curious if there is a way to execute another program from
w/in a C program.  Well, I know I can do that, but what I need to do is
send input to the other program I exectute.  Somewhere in the program it
asks for a few values and I dont't know how to give it the values from the
process that called it.  Is this possible, if so how might I do it.  If
anybody has sample code to do this I would appreciate it.
-- 
Mike Berry                  DISCLAIMER:  WHAT! A disclaimer!
Rochester, New York                      Next you'll ask for a resume.

{whatever}...rochester!ritcv!cci632!sjfc!mbp5756

guy@auspex.UUCP (Guy Harris) (03/14/89)

>I was just curious if there is a way to execute another program from
>w/in a C program.

There are a number of different ones for different operating systems. 
The only one that can be considered a part of C, rather than a part of
some particular operating system, is the "system" function, which is in
the December 7, 1988 dpANS.  However, the description of it indicates
that:

	1) not all implementations of C need *have* a "command
	   processor", and thus not all implementations of C need do
	   anything interesting with "system" except return 0 when you
	   pass it a null pointer of type "const char *" (the 0 return
	   value indicates that the implementation has no such "command
	   processor" and, therefore, that you may not be able to
	   execute any commands).

	2) the description says that the string you pass to "system" is
	   executed "in an implementation-defined manner", so you don't
	   have much in the way of guarantees about its behavior.

 
>Well, I know I can do that, but what I need to do is send input to the
>other program I exectute.

Well, there are ways to do that under UNIX, for example, but no way to
do it "in C", given the above.  There may well be ways to do it with
some particular C compiler in MS-DOS as well, and there may be ways of
doing it with other C compilers under other operating systems.

In other words, until you tell us under what operating system (and,
perhaps, with which C compiler) you intend to do this, we can't really
answer your question....