I'm automating compilation and execution of C++ programs (+100 programs) which some of them require user interaction.
Here is a sample of C++ program that requires user to insert a string:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string name;
cout << "Enter your name: ";
cin >> name;
cout << "your name is: " << name << endl;
return 0;
}
Here what I need is to compile it, execute it and redirect the output of the program to another file:
g++ -std=c++11 -o practice practice.cpp
To automate the input insertion I run the program as follows:
./practice <<< $(echo "Brian") >> result.txt
I know there are different ways of redirecting a string into program's STDIN like
echo "Brian" | ./practice >> result.txt
But all of them generate the following output:
Enter your name: your name is: Brian
What I want is to see below output instead:
Enter your name: Brian
your name is: Brian
I want the redirected string to appear in the output of the file, right after the line program requires user interaction.
Any suggestions?