小编pos*_*lon的帖子

如何将字符串推送到标准输入?在启动时通过stdin提供输入,然后以交互方式读取stdin输入

有没有办法在调用时将字符串"推"到程序的stdin流?

这样我们才能有效果

echo "something" | ./my_program
Run Code Online (Sandbox Code Playgroud)

但是,不是在读取EOF之后"something",my_program将从原始标准输入(例如,键盘)读取其进一步输入.

示例:假设我们要启动一个bash shell,但我们要在其中做的第一件事就是调用date.echo date | bash不会做这个工作,因为shell会在运行后终止date.

linux bash stdin interactive

3
推荐指数
1
解决办法
776
查看次数

标签 统计

bash ×1

interactive ×1

linux ×1

stdin ×1