Piping, etc

Hello,

I have a C++ code that depends on the output of a shell script, but also requires user input. If I pipe from the script into program then all of the user input cin's get piped into as well. How do I fix this?

Some code may help:

1
2
3
4
5
6
7

cin >> howMany; //I want this input to come from the script
                //This will always only be the first entry

cout << "what is your name" << endl;
cin >> name; //I want this to come from the terminal


Is there a way to open two streams, one from the pipe and the other from the terminal?

Thanks!
You could open a pipe with popen()
But as you only need just one thing at the beginning you could pass it as a command line argument
$ ./program.bin "$(./script.sh)"


I think that you can't generalize from just one example.
Thank you! popen() is exactly what I was looking for!
Topic archived. No new replies allowed.