system("type autoexec.bat");
while ( fgets(string, MAX, stdin) )
fputs(string, stderr);
OR
system("type autoexec.bat < thisprocess");
Thanks, and sorry for being off topic.
Mike
AFAIK this is "easy" because the routine that initiates the child-process
(sorry for using *NIX terminology) has to provide the handles for the
child's stdXXX (in/out/err). I don't think you can actually arrange a
UNIX-style pipe where you get the output as it's being generated because
DOS-style pipes don't work that way. Even from the command-line they
require an intermediate file. You could therefore do the same thing from
your program,
system( "type autoexec.bat >tempfile" )
and then open and read from tempfile.
I have a vague recollection that it's even possible to get the output on a
line-by-line (or char-by-char) basis with some really tricky programming
but I've been doing so much Linux and Windows programming lately that I
often have to look things up that I should know just to check how to do it
in the system I'm using at the moment.
Sorry I can't be more definite.
Norm
Since MS-DOS is a single-tasking system, it cannot be done as simply
as Unix's popen() function. (That function returns a handle to either
the child process' stdin or stdout, depending on how you call it.)
The best you could do is:
system("whatever >tempfile");
result = fopen("tempfile","rt");
and then fread() from result.
Note, of course, that your program does not run in parallel with the
child process, but rather will wait until the child exits before reading
from the result file.
--
+---------+----------------------------------+-----------------------------+
| Kenneth | kenbrody at spamcop.net | "The opinions expressed |
| J. | http://www.hvcomputer.com | herein are not necessarily |
| Brody | http://www.fptech.com | those of fP Technologies." |
+---------+----------------------------------+-----------------------------+
in comp.lang.c i read:
>Mike K <mki...@rogers.com> wrote in message
>news:_R7N8.272441$t8_....@news01.bloor.is.net.cable.rogers.com...
>>
>> Is it possible to use a system(x) call in a program, and catch the
>> output of x in the caller's stdin?
off topic for comp.lang.c (and comp.lang.c++).
> system( "type autoexec.bat >tempfile" )
>and then open and read from tempfile.
>
>I have a vague recollection that it's even possible to get the output on a
>line-by-line (or char-by-char) basis with some really tricky programming
fgets and fgetc are tricky?
--
bringing you boring signatures for 17 years