怎么用shell脚本执行C++的exe文件并且对它进行输入?

怎么用shell脚本执行C++的exe文件并且对它进行输入?

问题描述:

#include<iostream>
using std::cin;
using std::cout;
using std::endl;

int main() {
	int year,day;
	cin>>year>>day;
	cout<<year<<" "<<day<<endl;
	return 0;
}

如上,我想编写一个脚本,它会自动编译这个文件并且执行生成的exe文件并且可以自动输入两个整数,我用的windows,我下载了bash但是目前仅仅只能到编译并执行的程度,必须要我手动输入两个整数,以下是我的脚本里的东西

g++ nextDate.cpp -o nextDate
./nextDate 2000 2 28
echo "2000 2 28"

可以把要输入的数据存入文本文件,在shell脚本里调用./nextDate时重定向输入输入呀。

echo 2000 2 28 >input.txt

./nextDate

 

或者不村文件而直接用管道

echo 2000 2 28 | ./nextDate