包括
假设这是我正在运行的代码:
int main(int argc, char **argv) {
bool running = true;
string lineInput;
while (running)
{
while (cin >> lineInput)
{
cout << lineInput;
}
}
return 0;
}
我想发生的事情是,我可以通过键入“ ./myProgram”从终端调用启动程序。我不确定该怎么做的部分是使它能够在稍后的时间键入
echo "some text to echo" | myProgram
并能够让我的程序然后将文本打印回终端。现在,只有输入以下内容,我才能使其工作:
echo "blah blah blah" | ./myProgram
所以我的目标是有两个单独的步骤。一个在我启动程序的地方,另一个在我通过管道输入一些要使用的东西时
最佳答案
我想您可以使用命名管道来执行此操作。
mkfifo mypipe
./myProgram < mypipe &
cat file1.txt file2.txt file3.txt > mypipe
关于c++ - 用管道输入到已经运行的cpp程序?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20724398/