[英]How to capture command output from command waiting for input?
I have a command that I want to parse. 我有一个要解析的命令。 However, this command, in certain scenarios, will prompt if it needs user-intervention (eg yes/no, [enter] to continue, etc.).
但是,在某些情况下,该命令将提示是否需要用户干预(例如,是/否,[输入]以继续,等等)。 How to I capture the output from this command while showing all the output?
显示所有输出时如何捕获此命令的输出? If the command waits for input, it'll look like the command is busy executing when it's really at a prompt.
如果命令等待输入,则实际上在提示时,命令似乎正在忙于执行。
$ program_output=$(command)
# Program stalls here performing a `read` but user doesn't see anything
# User finally presses [Enter]
$
$ command
Warning: Some warning message. Continue? (Y/n)
Y #User-input
Created http://example/subprogram/id/
$
If you are capturing stdout, you could print a message on stderr to provide feedback: 如果要捕获标准输出,则可以在标准错误上打印一条消息以提供反馈:
echo -n 'Warning: Some warning message. Continue? (Y/n) ' >&2
read -r answer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.