Hi,
I am trying to execute the program "upper" (code in upper.c) from "useupper" (code in useupper.c) with input redirection for "upper".
Both the codes compile fine. But when I am running "useupper", the program waits for input and does not convert and show in uppercase the contents of "new.txt" (in which I have put some lowercase text).
linux:~/prog # gcc -o useupper useupper.c
linux:~/prog # gcc -o upper upper.c
linux:~/prog #./useupper new.txt
... waits for some input here ...
Code:
// useupper.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
if(argc != 2){
fprintf(stderr,"usage: useupper file\n");
exit(1);
}
execl("./upper", "upper", "<", argv[1], 0);
perror("could not exec ./upper");
exit(3);
}
Code:
// upper.c
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int main()
{
int ch;
while((ch = getchar()) != EOF)
putchar(toupper(ch));
exit(0);
}
"upper" itself works fine.
linux:~/prog # ./upper<new.txt
THIS TEXT WAS IN LOWERCASE IN FILE.
linux:~/prog #
Why is the text in "new.txt" not converted to uppercase when "upper" is run with execl() and redirection by "useupper"?
Thanks and regards,
Arun