From: Vandana on
Thanks Eric, I was doing more than just modifying the command line
args that is why I used fork.
Parent process was also reading in from the stdin.

My approach seems to work, I was in doubt whether it is the cleanest
way to do it.

Thanks for your inputs.

On Feb 18, 12:41 pm, Eric Sosman <esos...(a)ieee-dot-org.invalid> wrote:
> On 2/18/2010 2:21 PM, Vandana wrote:
>
> > Hi,
>
> >      I would like to know how to redirect the stdin of the parent
> > process to the child process.
>
> > In my program on the command line, I pass the input file. For ex:
>
> > ./a.out (command line options)<  in.txt
>
> > In the C Program, I create a copy of the argv, this is because the
> > child process needs to be run with small modifications in the command
> > line parameters. Now I create the copy, make the modifications, then
> > after the fork, for the child process I use the modified command line
> > parameters. Is there a cleaner way to do this. Also, how do I make the
> > child process read the input from in.txt?
>
>      Although you're writing in C, your question is not about
> the C language but about the environment your program runs in.
> A Unix-oriented forum like comp.unix.programmer will be able to
> give you better help.
>
> <off-topic>
>
>      1) If all the parent does is modify the command-line and
> then launch the child, fork() doesn't seem necessary: Just do
> the execXX() in the parent.
>
>      2) All the parent's file descriptors are inherited by the
> child, including descriptor 0.  The only likely problem is if
> the parent has already read something from stdin, and the I/O
> library has read a little extra and is holding it in a buffer:
> The buffer and its contents, if any, are *not* inherited.  But
> if you haven't touched stdin, there should be no difficulty.
>
>      3) If I'm wrong about either of (1) and (2), check with the
> experts in comp.unix.programmer to find out about it.  Follow-ups
> set.
>
> </off-topic>
>
> --
> Eric Sosman
> esos...(a)ieee-dot-org.invalid

 | 
Pages: 1
Prev: ANN: Seed7 Release 2010-02-21
Next: integer