V
Vandana
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?
int main(int argc, char*argv[]) {
char *argv_parent[];
char *argv_child[];
/*create a copy of the argv */
argv_parent = duplicate(argv);
argv_child = {"xx",yy", NULL};
process_id = fork()
if (process_id == 0) {
/* this is child process */
argv = argv_child;
} else
/* parent process */
argv = argv_parent;
return 0;
}
I run the program like this
../a.out (command line options) < in.txt
My program seems to work, but I dont know how to pass the input file
(in.txt) to the child process.
Could someone please help me.
Thanks,
Vandana
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?
int main(int argc, char*argv[]) {
char *argv_parent[];
char *argv_child[];
/*create a copy of the argv */
argv_parent = duplicate(argv);
argv_child = {"xx",yy", NULL};
process_id = fork()
if (process_id == 0) {
/* this is child process */
argv = argv_child;
} else
/* parent process */
argv = argv_parent;
return 0;
}
I run the program like this
../a.out (command line options) < in.txt
My program seems to work, but I dont know how to pass the input file
(in.txt) to the child process.
Could someone please help me.
Thanks,
Vandana