I have a very simple program :
void main()
{
fgets(buf,133,stdin);
printf( buf);
system("/bin/dash");
}
When I launch the program, it all works fine, I can type whatever I want and then I have a shell. However if I do
$ echo 'blabla' | ./test
in order to automatically fill the buf (without typing anyting with the keyboard), the shell is executed, though, /bin/ls works fine for instance. (apparently the display commands work fine)
If I remove the fgets line, and I execute the same command, it works but takes the 'blabla' as an argument for /bin/dash. However adding a nul character or a return '\xd' in order to simulate the return of my keyboard in the fgets doesn't work
I'd like to understand what happens when I use the '|' symbol within my c++ program. I thought it was the solution to automatically fill scanfs and fgets without any human interaction, am I doing it wrong or is there an other solution ?
Thank you.
Debian, C++ g++