从文件内容切换到标准输入管道中的命令? (Linux的壳牌) [英] Switch from file contents to STDIN in piped command? (Linux Shell)

查看:121
本文介绍了从文件内容切换到标准输入管道中的命令? (Linux的壳牌)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序(即我没有写),它的目的不是从一个文件中的命令来读取。 STDIN上输入命令是pretty繁琐,所以我希望能够通过重新使用文件中写入的命令给它自动化。麻烦的是,如果程序碰到EOF,它无限循环试图在未来的命令来读取屏幕上下探菜单选项的奔流不息。

I have a program (that I did not write) which is not designed to read in commands from a file. Entering commands on STDIN is pretty tedious, so I'd like to be able to automate it by writing the commands in a file for re-use. Trouble is, if the program hits EOF, it loops infinitely trying to read in the next command dropping an endless torrent of menu options on the screen.

我希望能够做的就是猫通过管道包含命令进入程序的文件,然后使用某种形式的外壳魔法有它从文件到标准输入切换,当它击中文件的EOF。

What I'd like to be able to do is cat a file containing the commands into the program via a pipe, then use some sort of shell magic to have it switch from the file to STDIN when it hits the file's EOF.

请注意:我使用的猫已经被认为' - '为标准输入。不幸的是(我不知道在此之前),管道命令等待第一个程序的输出,以启动第二程序之前终止 - 他们不并行运行。如果有一些办法让程序在那种管道行动并行运行,将工作!

Note: I've already considered using cat with the '-' for STDIN. Unfortunately (I didn't know this before), piped commands wait for the first program's output to terminate before starting the second program -- they do not run in parallel. If there's some way to get the programs to run in parallel with that kind of piping action, that would work!

有什么想法?感谢您的任何帮助!

Any thoughts? Thanks for any assistance!

编辑:

我要指出,我的目标不仅是prevent击中的命令文件的末尾制度。我希望能够继续从键盘输入的命令文件时碰到EOF。

I should note that my goal is not only to prevent the system from hitting the end of the commands file. I would like to be able to continue typing in commands from the keyboard when the file hits EOF.

推荐答案

我会做这样的事情。


(cat your_file_with_commands; cat) | sh your_script

这样,当用命令的文件完成后,第二个将与任何你键入的标准输入以后养活你的脚本。

That way, when the file with commands is done, the second cat will feed your script with whatever you type on stdin afterwards.

这篇关于从文件内容切换到标准输入管道中的命令? (Linux的壳牌)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆